Introduction to Graph Data Structure (original) (raw)

Last Updated : 24 Nov, 2025

A graph is a non-linear data structure made up of vertices (nodes) and edges (connections) that represent relationships between objects. Unlike arrays or linked lists, graphs do not follow a sequential order.
Example: On a map, each city is a vertex, and each road connecting two cities is an edge. This way, a graph represents how cities are linked.

introduction_to_graphs

Components of Graph Data Structure

Types OfGraphs in Data Structure and Algorithms

A graph can be divided into multiple categories based on different properties such as edges, direction, connectivity and many others.

Based on weight :

1. Weighted Graphs

A weighted graph is a graph where each edge has a number (weight) that represents distance, cost, or time.

w

2. Unweighted Graphs

An **unweighted graph is a graph where all edges are treated equally, with no extra values like distance or cost.

dense

Based on Edge Direction:

3. Undirected Graph

A graph in which edges do not have any direction. That is the nodes are unordered pairs in the definition of every edge.

4. Directed Graph

A graph in which edge has direction. That is the nodes are ordered pairs in the definition of every edge.

**For More Refer this Article: Types Of Graph

Representation of Graph Data Structure:

There are multiple ways to store a graph: The following are the most common representations.

Adjacency Matrix Representation of Graph Data Structure:

In this method, the graph is stored in the form of the 2D matrix where rows and columns denote vertices. Each entry in the matrix represents the weight of the edge between those vertices.

matrix[i][j] = 1 if there is an edge between vertex i and vertex j.
matrix[i][j] = 0 if there is no edge.

adjacency_mat1-(1)-copy

Adjacency List Representation of Graph:

This graph is represented as a collection of array lists. There is an array of pointer which points to the edges connected to that vertex.

**For More Refer this Article : Represent graph using adj list and mat

Difference between Tree and Graph:

Tree is a restricted type of Graph Data Structure, just with some more rules. Every tree will always be a graph but not all graphs will be trees. Linked List, Trees, and Heaps all are special cases of graphs.

**For More Refer this Article : Trees vs Graph

Traversal Technique of Graph:

Traversal techniques are used to visit all the vertices of a graph systematically. These methods help to explore the graph completely and are useful for solving many graph-related problems.

Depth First Search (DFS):

**For More Refer this Article : Depth First Search

Breadth First Search (BFS)

**For More Refer this Article : Breadth First Search

Real-Life Applications of Graph Data Structure:

Graph Data Structure has numerous real-life applications across various fields. Some of them are listed below:

Advantages of Graph Data Structure: