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

Representation of Graph

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Representation of Graph

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

UNIT IV

Basic terminology – Representation of Graph- Graph traversal –


Graph Algorithms
Representation of Graph
✓ Graphs in data structures are used to
represent the relationships between objects.

✓ Every graph consists of a set of points


known as vertices or nodes connected by
lines known as edges.

✓ The vertices in a network represent entities.


Representation of Graph
Graph representations are
✓ Adjacency matrix

✓ Adjacency list
Adjacency Matrix
✓ A sequential representation is an adjacency
matrix.
✓ It shows which nodes are next to one another.
✓ Create M x M matrix.
✓ If an edge exists between vertex a and b, the
corresponding element of G, G = 1, otherwise 0.
✓ If there is a weighted graph, and record the edge's
weight instead of 1s and 0s.
Adjacency Matrix -Directed Graph Representation
Adjacency Matrix -Undirected Graph Representation
Adjacency Matrix -
Weighted Directed Graph Representation
✓ Weight or cost is indicated at the graph's edge,
✓ a weighted graph representing these values in the
matrix.
Adjacency Matrix -
Weighted UnDirected Graph Representation
✓ Weight or cost is indicated at the graph's edge,
✓ a weighted graph representing these values in the
matrix.
Adjacency List-
Weighted Directed Graph Representation
✓ An adjacency list is used in the linked
representation to store the Graph in the
computer's memory.
✓ It is maintained for each node present in the graph,
which stores the node value and a pointer to the
next adjacent node.
✓ If all the adjacent nodes are traversed, then store
the NULL in the pointer field of the last node of the
list.
Adjacency List-
Directed Graph Representation

For a directed graph, the sum of the lengths of adjacency


lists is equal to the number of edges present in the graph
Adjacency List-
Undirected Graph Representation

For an undirected graph, The sum of the lengths of


adjacency lists is equal to twice the number of edges
present in an undirected graph.
Adjacency List-
Weighted Directed Graph Representation

✓ Here, each node contains an extra field ie. weight of the


node.
✓ In an adjacency list, it is easy to add a vertex.
✓ using the linked list, it saves space.
Operations on Graphs

✓ Creating graphs
✓ Insert vertex
✓ Delete vertex
✓ Insert edge
✓ Delete edge
Creating Graphs
There are two techniques to make a graph:

1. Adjacency Matrix 2. Adjacency List


✓is a matrix with rows ✓A finite graph is
and columns labeled represented by an
by graph vertices. adjacency list.
✓1 or 0 whether they are ✓ It describes the set of
adjacent or not. neighbors of a particular
vertex.
Insert Vertex
✓ Introducing one or more vertices or nodes,
✓ the graph's size grows by one,
✓ increasing the matrix's size by one at the row and
column levels.
Delete Vertex
✓ removing a specific node or vertex from a graph.
Insert Edge
✓ Connecting two provided vertices can be used to
add an edge to a graph.
Delete Edge
✓ The connection between the vertices or nodes
can be removed to delete an edge.
The way to get
started is to quit
talking and
begin doing.
Walt Disney
THANK YOU

You might also like