All About Graph Data Structure - Introduction

All About Graph Data Structure - Introduction

·

3 min read

Hey guys! Welcome to a new blog today we will be learning about graph data structure. The graph is one of the most realistic data structures by realistic what I mean I will be telling it later on.

What are Graphs?

The graphs simply mean connections. It is a pictorial representation of objects and Pairs are connected. If not all then most of them. Before going into details we need to understand why we need graph data structure and the very usage of graph data structure.

Graph Basics

Graphs have:-

  1. Vertices - Every node of a graph is its vertices. so talking about this diagram the vertices of these graphs will be {a,b,c,d,e}

  2. Edges - Edges are the paths between the two vertices. eg. {ab,ac, bd,cd,de}

  3. Path- It is the sequence of edges like in the above diagram {ABDE} is a path.

Importance of Graphs Data Structure

When there is a relationship between the different components and graphs data structure comes in handy as it helps in modelling and storing data.

Now the question is why graphs can do that. Well, Graphs can represent complex relationships and connections more flexibly and intuitively in comparison to other data structures like arrays, trees, and so on.

Examples

Graphs can be used to represent the road network of the city where vertices of the graph can represent the intersections between roads and the edges represent the roads themselves.

In fact, on social networking sites graphs have their importance as their vertices represent individuals and edges represent their connections. So all your social media platforms you use like Instagram. Facebook, Snapchat, etc, implement graphs in their code base.

That is why I said the graph is the realistic data structure above.

Types of Graphs

Graphs are of two types directed and undirected.

  1. Directed graphs - It is also known as digraphs, It is a type of graph that consists of a set of vertices connected by edges where edges have a direction associated with them.

    Check whether a directed graph is Eulerian | Techie Delight

  2. Undirected Graph - It is the opposite of the directed one, as it is a graph where edges have no directions associated with them. It simply means that the edges of an undirected graph do not point to any directed direction.

    Undirected graphs do not have any concept of "incoming" and "outgoing" and all edges will be having two-way connections.

    3: An undirected graph with 7 nodes and 7 edges. | Download Scientific  Diagram

Sum Up

This article was all about the introduction of the graph data structure. In the next article of this series, we will be covering graph implementation.

If you liked this article then please share and subscribe to the newsletter.

Thanks!

Did you find this article valuable?

Support Ishan Gaur by becoming a sponsor. Any amount is appreciated!