What is a Graph?

This lesson is a brief introduction to the graph data structure, its types, and the standard terminologies used to describe it.

Introduction

When we talk 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. We will also look at how they are used to solve a diverse range of problems.

Now, let’s talk about what a graph really is.

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 uni-directional or bi-directional depending on your graph. An edge can also have a cost associated with it (will be discussed in detail later).

Here is a visual representation of a graph:

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