What is a Graph?

A brief introduction to the graph data structure, its types, and the standard terminologies used to describe it.

Introduction

When talking about graphs, what comes to mind are the conventional graphs used to model data. In computer science, the term “graph” has a completely different meaning.

The graph data structure plays a fundamental role in several applications such as GPS, neural networks, peer to peer networks, search engine crawlers, and even social networking websites.

This section will explore their functionality and power. You will also look at how they are used to solve a diverse range of problems.

Now, What is a graph?

Graph structure

A graph is a set of nodes that are connected to each other in the form of a network. First of all, we’ll define the two basic components of a graph.

Vertex

A vertex is the most essential part of a graph. A collection of vertices forms a graph. In that sense, vertices are similar to linked list nodes.

Edge

An edge is the link between two vertices. It can be unidirectional or bidirectional depending on your graph. An edge can also have a cost associated with it (this will be discussed in detail later on).

Here is a visual representation of a graph:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.