0% found this document useful (0 votes)
45 views

Graph Data Structure: Learning Outcomes: 1. Understand What Is A Graph 2. Types of Graphs 3. Representing Graphs

A graph is a collection of objects called vertices connected by relationships called edges. There are two main types of graphs: directed graphs where edges have orientations and undirected graphs where edges are not oriented. Graphs can be represented using an adjacency matrix, which is a table showing which vertices are connected, or an adjacency list, which lists the neighbors of each vertex.

Uploaded by

VISHAL MUKUNDAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Graph Data Structure: Learning Outcomes: 1. Understand What Is A Graph 2. Types of Graphs 3. Representing Graphs

A graph is a collection of objects called vertices connected by relationships called edges. There are two main types of graphs: directed graphs where edges have orientations and undirected graphs where edges are not oriented. Graphs can be represented using an adjacency matrix, which is a table showing which vertices are connected, or an adjacency list, which lists the neighbors of each vertex.

Uploaded by

VISHAL MUKUNDAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Graph Data Structure

Learning Outcomes:
1. Understand what is a Graph
2. Types of graphs
3. Representing graphs

Graphs:

A Graph is a finite collection of objects and relations existing between objects. If we represent
objects as vertices(or nodes) and relations as edges then we can get following two types of
graph:-

Directed Graphs: In directed graph, an edge is represented by an ordered pair of vertices (i,j) in
which edge originates from vertex i and terminates on vertex j. Given below is an example of an
directed graph.
Fig: D.1
Undirected Graphs: In Undireced graph, edges are represented by unordered pair of
vertices.Given below is an example of an undirected graph.
Fig: UD.1

Representation
The two most common ways of representing graphs are:
1. Adjacency matrix
2. Adjacency List

Adjacency Matrix
Let us consider a graph in which there are N vertices numbered from 0 to N-1 and E number of
edges in the form (i,j). Where (i,j) represent an edge originating from ith vertex and terminating
on jth vertex. Now, A Adjacency Matrix is a N*N binary matrix in which value of [i,j]th cell
is 1 if there exists an edge originating from ith vertex and terminating to jth vertex, otherwise the
value is 0. Given below are Adjacency matrices for both Directed and Undirected graph shown
above:

Adjacency Matix for Directed Graph: (For FIG: D.1)


Adjacency Matix for Undirected Graph: (For FIG: UD.1)

Adjacency List

Lets consider a graph in which there are N vertices numbered from 0 to N-1 and E number of
edges in the form (i,j). Where (i,j) represent an edge from ith vertex to jth vertex.
Now, Adjacency List is an array of seperate lists. Each element of array is a list of
corresponding neighbour(or directly connected) vertices.In other words ith list of Adjacency
List is a list of all those vertices which is directly connected to ith vertex. Given below are
Adjacency lists for both Directed and Undirected graph shown above:

Adjacency List for Directed Graph: (For FIG: D.1)


Adjacency List for Undirected Graph: (For FIG: UD.1)

You might also like