SlideShare a Scribd company logo
1 of 23
BY
S.RAGAVI
I-MSC(CS)
NADAR SARASWATHI COLLEGE OF ARTS AND
SCIENCE
 A graph G consists of two sets
– a finite, nonempty set of vertices V(G)
– a finite, possible empty set of edges E(G)
– G(V,E) represents a graph
 An undirected graph is one in which the
pair of vertices in a edge is unordered, (v0,
v1) = (v1,v0)
 A directed graph is one in which each
edge is a directed pair of vertices, <v0,
v1> != <v1,v0>
Examples for Graph
0
1 2
3
0
1
2
0
1 2
3 4 5 6
G1
G2
G3
V(G1)={0,1,2,3} E(G1)={(0,1),(0,2),(0,3),(1,2),(1,3),(2,3
V(G2)={0,1,2,3,4,5,6} E(G2)={(0,1),(0,2),(1,3),(1,4),(2,5),(2,6
V(G3)={0,1,2} E(G3)={<0,1>,<1,0>,<1,2>}
complete undirected graph: n(n-1)/2 edges
complete directed graph: n(n-1) edges
complete graph incomplete graph
• A Complete graph is a graph that has the
maximum number of edges
- for undirected graph with n vertices, the
maximum number of
edges is n(n-1)
- for directed graph with n vertices, the
maximum number of edges is n(n-1)
-example: G is a complete graph
Adjacent and Incident
 If (v0, v1) is an edge in an undirected graph
– v0 and v1 are adjacent
– The edge (v0, v1) is incident on vertices v0 and
 If <v0, v1> is an edge in a directed graph
– v0 is adjacent to v1, and v1 is adjacent from v0
– The edge <v0, v1> is incident on v0 and v1
0 2
1
(a)
2
1
0
3
(b)
Example of a graph with feedback loops and a
multigraph (p.260)
self edge multigraph:
multiple occurrences
of the same edge
 A subgraph of G is a graph G’ such that V(G’)
is a subset of V(G) and E(G’) is a subset of
E(G)
 A path from vertex vp to vertex vq in a graph G,
is a sequence of vertices, vp, vi1, vi2, ..., vin, vq,
such that (vp, vi1), (vi1, vi2), ..., (vin, vq) are edges
in an undirected graph
 The length of a path is the number of edges
on it
0 0
1 2 3
1 2 0
1 2
3
(i) (ii) (iii) (iv)
(a) Some of the subgraph of G1
0 0
1
0
1
2
0
1
2
(i) (ii) (iii) (iv)
(b) Some of the subgraph of G3
0
1 2
3
G1
0
1
2
G3
 A simple path is a path in which all vertices,
except possibly the first and the last, are
distinct
 A cycle is a simple path in which the first and
the last vertices are the same
 In an undirected graph G, two vertices, v0 an
v1, are connected if there is a path in G from
to v1
 An undirected graph is connected if, for ever
pair of distinct vertices vi, vj, there is a path
0
1 2
3
0
1 2
3 4 5 6
G1
G2
connected
tree (acyclic graph)
 A connected component of an undirected
graph
is a maximal connected subgraph.
 A tree is a graph that is connected and acyc
 A directed graph is strongly connected if the
is a directed path from vi to vj and also
from vj to vi.
 A strongly connected component is a maxim
subgraph that is strongly connected.
Graph Representations
 Adjacency Matrix
 Adjacency Lists
 Adjacency Multilists
Adjacency Matrix
 Let G=(V,E) be a graph with n vertices.
 The adjacency matrix of G is a two-dimensiona
n by n array, say adj_mat
 If the edge (vi, vj) is in E(G), adj_mat[i][j]=1
 If there is no such edge in E(G), adj_mat[i][j]=0
 The adjacency matrix for an undirected graph is
symmetric; the adjacency matrix for a digraph
need not be symmetric
Examples for Adjacency Matrix
0
1
1
1
1
0
1
1
1
1
0
1
1
1
1
0












0
1
0
1
0
0
0
1
0










0
1
1
0
0
0
0
0
1
0
0
1
0
0
0
0
1
0
0
1
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
1
0
0
0
0
0
0
1
0
1
0
0
0
0
0
0
1
0


























G
1
G2
G4
0
1 2
3
0
1
2
1
0
2
3
4
5
6
7
symmetric
undirected: n2/2
directed: n2
Merits of Adjacency Matrix
 From the adjacency matrix, to determine
the connection of vertices is easy
 The degree of a vertex is
 For a digraph, the row sum is the
out_degree, while the column sum is the
in_degree
adj mat i j
j
n
_ [ ][ ]


0
1
ind vi A j i
j
n
( ) [ , ]



0
1
outd vi A i j
j
n
( ) [ , ]



0
1
Data Structures for Adjacency
Lists
#define MAX_VERTICES 50
typedef struct node *node_pointer;
typedef struct node {
int vertex;
struct node *link;
};
node_pointer graph[MAX_VERTICES];
int n=0; /* vertices currently in use
*/
Each row in adjacency matrix is represented as an adjacency list.
0
1
2
3
0
1
2
0
1
2
3
4
5
6
7
1 2 3
0 2 3
0 1 3
0 1 2
G1
1
0 2
G3
1 2
0 3
0 3
1 2
5
4 6
5 7
6
G4
0
1 2
3
0
1
2
1
0
2
3
4
5
6
7
An undirected graph with n vertices and e edges ==> n head nodes and 2e list nodes
marked vertex1 vertex2 path1 path2
An edge in an undirected graph is
represented by two nodes in adjacency list
representation.
Adjacency Multilists
–lists in which nodes may be shared among
several lists.
(an edge is shared by two different paths)
0 1 N2 N4
0 2 N3 N4
0 3 N5
1 2 N5 N6
1 3 N6
2 3
N
1
N
2
N
3
N
0
1
2
3
edge (0,1)
edge (0,2)
edge (0,3)
edge (1,2)
edge (1,3)
edge (2,3)
(1,0)
(2,0)
(3,0)
(2,1)
(3,1)
(3,2)
0
1 2
3
six edges
Lists: vertex 0: M1->M2->M3, vertex 1: M1->M4->M5
vertex 2: M2->M4->M6, vertex 3: M3->M5->M6
typedef struct edge *edge_pointer;
typedef struct edge {
short int marked;
int vertex1, vertex2;
edge_pointer path1, path2;
};
edge_pointer graph[MAX_VERTICES];
marked vertex1 vertex2 path1 path2
Some Graph Operations
 Traversal
Given G=(V,E) and vertex v, find all wV,
such that w connects v.
– Depth First Search (DFS)
preorder tree traversal
– Breadth First Search (BFS)
level order tree traversal
 Connected Components
 Spanning Trees
Graph G and its adjacency lists
depth first search: v0, v1, v3, v7, v4, v5, v2, v6
breadth first search: v0, v1, v2, v3, v4, v5, v6, v7
Graph representation

More Related Content

What's hot

Graph data structure
Graph data structureGraph data structure
Graph data structure
Tech_MX
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
Abhishek Pachisia
 

What's hot (18)

Graph theory
Graph theoryGraph theory
Graph theory
 
Grpahs in Data Structure
Grpahs in Data StructureGrpahs in Data Structure
Grpahs in Data Structure
 
Graph theory
Graph theory Graph theory
Graph theory
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Graph
GraphGraph
Graph
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
 
Graph
GraphGraph
Graph
 
Ppt of graph theory
Ppt of graph theoryPpt of graph theory
Ppt of graph theory
 
Graphss
GraphssGraphss
Graphss
 
Connectivity of graphs
Connectivity of graphsConnectivity of graphs
Connectivity of graphs
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Graph theory presentation
Graph theory presentationGraph theory presentation
Graph theory presentation
 
Graph theory concepts complex networks presents-rouhollah nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabati
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Graphs
GraphsGraphs
Graphs
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Graphs
GraphsGraphs
Graphs
 

Similar to Graph representation

Discrete maths assignment
Discrete maths assignmentDiscrete maths assignment
Discrete maths assignment
Keshav Somani
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
Victor Palmar
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
Anuj Modi
 

Similar to Graph representation (20)

Chap 6 Graph.ppt
Chap 6 Graph.pptChap 6 Graph.ppt
Chap 6 Graph.ppt
 
graph.pptx
graph.pptxgraph.pptx
graph.pptx
 
chapter6.PPT
chapter6.PPTchapter6.PPT
chapter6.PPT
 
Dsa.PPT
Dsa.PPTDsa.PPT
Dsa.PPT
 
Graphs
GraphsGraphs
Graphs
 
09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
DATA STRUCTURES unit 4.pptx
DATA STRUCTURES unit 4.pptxDATA STRUCTURES unit 4.pptx
DATA STRUCTURES unit 4.pptx
 
Graph in Data Structure
Graph in Data StructureGraph in Data Structure
Graph in Data Structure
 
Discrete maths assignment
Discrete maths assignmentDiscrete maths assignment
Discrete maths assignment
 
Matrix representation of graph
Matrix representation of graphMatrix representation of graph
Matrix representation of graph
 
Graph
GraphGraph
Graph
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structures
 
graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________
 
graph theory
graph theorygraph theory
graph theory
 
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfClass01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph ColouringGraph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
Cs6702 graph theory and applications 2 marks questions and answers
Cs6702 graph theory and applications 2 marks questions and answersCs6702 graph theory and applications 2 marks questions and answers
Cs6702 graph theory and applications 2 marks questions and answers
 

More from DEEPIKA T (20)

See
SeeSee
See
 
71619109 configuration-management.pdf (1) (1)
71619109 configuration-management.pdf (1) (1)71619109 configuration-management.pdf (1) (1)
71619109 configuration-management.pdf (1) (1)
 
80068
8006880068
80068
 
242296
242296242296
242296
 
Data mining
Data miningData mining
Data mining
 
Parallelizing matrix multiplication
Parallelizing  matrix multiplicationParallelizing  matrix multiplication
Parallelizing matrix multiplication
 
Health care in big data analytics
Health care in big data analyticsHealth care in big data analytics
Health care in big data analytics
 
Ajax
AjaxAjax
Ajax
 
Role of human interaction
Role of human interactionRole of human interaction
Role of human interaction
 
Basic analtyics &amp; advanced analtyics
Basic analtyics &amp; advanced analtyicsBasic analtyics &amp; advanced analtyics
Basic analtyics &amp; advanced analtyics
 
Soap,Rest&Json
Soap,Rest&JsonSoap,Rest&Json
Soap,Rest&Json
 
Applet (1)
Applet (1)Applet (1)
Applet (1)
 
Jdbc ja
Jdbc jaJdbc ja
Jdbc ja
 
Appletjava
AppletjavaAppletjava
Appletjava
 
Remote method invocation
Remote  method invocationRemote  method invocation
Remote method invocation
 
Al
AlAl
Al
 
Presentation2
Presentation2Presentation2
Presentation2
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Topological sort
Topological sortTopological sort
Topological sort
 
Path compression
Path compressionPath compression
Path compression
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Graph representation

  • 2.  A graph G consists of two sets – a finite, nonempty set of vertices V(G) – a finite, possible empty set of edges E(G) – G(V,E) represents a graph  An undirected graph is one in which the pair of vertices in a edge is unordered, (v0, v1) = (v1,v0)  A directed graph is one in which each edge is a directed pair of vertices, <v0, v1> != <v1,v0>
  • 3. Examples for Graph 0 1 2 3 0 1 2 0 1 2 3 4 5 6 G1 G2 G3 V(G1)={0,1,2,3} E(G1)={(0,1),(0,2),(0,3),(1,2),(1,3),(2,3 V(G2)={0,1,2,3,4,5,6} E(G2)={(0,1),(0,2),(1,3),(1,4),(2,5),(2,6 V(G3)={0,1,2} E(G3)={<0,1>,<1,0>,<1,2>} complete undirected graph: n(n-1)/2 edges complete directed graph: n(n-1) edges complete graph incomplete graph
  • 4. • A Complete graph is a graph that has the maximum number of edges - for undirected graph with n vertices, the maximum number of edges is n(n-1) - for directed graph with n vertices, the maximum number of edges is n(n-1) -example: G is a complete graph
  • 5. Adjacent and Incident  If (v0, v1) is an edge in an undirected graph – v0 and v1 are adjacent – The edge (v0, v1) is incident on vertices v0 and  If <v0, v1> is an edge in a directed graph – v0 is adjacent to v1, and v1 is adjacent from v0 – The edge <v0, v1> is incident on v0 and v1
  • 6. 0 2 1 (a) 2 1 0 3 (b) Example of a graph with feedback loops and a multigraph (p.260) self edge multigraph: multiple occurrences of the same edge
  • 7.  A subgraph of G is a graph G’ such that V(G’) is a subset of V(G) and E(G’) is a subset of E(G)  A path from vertex vp to vertex vq in a graph G, is a sequence of vertices, vp, vi1, vi2, ..., vin, vq, such that (vp, vi1), (vi1, vi2), ..., (vin, vq) are edges in an undirected graph  The length of a path is the number of edges on it
  • 8. 0 0 1 2 3 1 2 0 1 2 3 (i) (ii) (iii) (iv) (a) Some of the subgraph of G1 0 0 1 0 1 2 0 1 2 (i) (ii) (iii) (iv) (b) Some of the subgraph of G3 0 1 2 3 G1 0 1 2 G3
  • 9.  A simple path is a path in which all vertices, except possibly the first and the last, are distinct  A cycle is a simple path in which the first and the last vertices are the same  In an undirected graph G, two vertices, v0 an v1, are connected if there is a path in G from to v1  An undirected graph is connected if, for ever pair of distinct vertices vi, vj, there is a path
  • 10. 0 1 2 3 0 1 2 3 4 5 6 G1 G2 connected tree (acyclic graph)
  • 11.  A connected component of an undirected graph is a maximal connected subgraph.  A tree is a graph that is connected and acyc  A directed graph is strongly connected if the is a directed path from vi to vj and also from vj to vi.  A strongly connected component is a maxim subgraph that is strongly connected.
  • 12. Graph Representations  Adjacency Matrix  Adjacency Lists  Adjacency Multilists
  • 13. Adjacency Matrix  Let G=(V,E) be a graph with n vertices.  The adjacency matrix of G is a two-dimensiona n by n array, say adj_mat  If the edge (vi, vj) is in E(G), adj_mat[i][j]=1  If there is no such edge in E(G), adj_mat[i][j]=0  The adjacency matrix for an undirected graph is symmetric; the adjacency matrix for a digraph need not be symmetric
  • 14. Examples for Adjacency Matrix 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0             0 1 0 1 0 0 0 1 0           0 1 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0                           G 1 G2 G4 0 1 2 3 0 1 2 1 0 2 3 4 5 6 7 symmetric undirected: n2/2 directed: n2
  • 15. Merits of Adjacency Matrix  From the adjacency matrix, to determine the connection of vertices is easy  The degree of a vertex is  For a digraph, the row sum is the out_degree, while the column sum is the in_degree adj mat i j j n _ [ ][ ]   0 1 ind vi A j i j n ( ) [ , ]    0 1 outd vi A i j j n ( ) [ , ]    0 1
  • 16. Data Structures for Adjacency Lists #define MAX_VERTICES 50 typedef struct node *node_pointer; typedef struct node { int vertex; struct node *link; }; node_pointer graph[MAX_VERTICES]; int n=0; /* vertices currently in use */ Each row in adjacency matrix is represented as an adjacency list.
  • 17. 0 1 2 3 0 1 2 0 1 2 3 4 5 6 7 1 2 3 0 2 3 0 1 3 0 1 2 G1 1 0 2 G3 1 2 0 3 0 3 1 2 5 4 6 5 7 6 G4 0 1 2 3 0 1 2 1 0 2 3 4 5 6 7 An undirected graph with n vertices and e edges ==> n head nodes and 2e list nodes
  • 18. marked vertex1 vertex2 path1 path2 An edge in an undirected graph is represented by two nodes in adjacency list representation. Adjacency Multilists –lists in which nodes may be shared among several lists. (an edge is shared by two different paths)
  • 19. 0 1 N2 N4 0 2 N3 N4 0 3 N5 1 2 N5 N6 1 3 N6 2 3 N 1 N 2 N 3 N 0 1 2 3 edge (0,1) edge (0,2) edge (0,3) edge (1,2) edge (1,3) edge (2,3) (1,0) (2,0) (3,0) (2,1) (3,1) (3,2) 0 1 2 3 six edges Lists: vertex 0: M1->M2->M3, vertex 1: M1->M4->M5 vertex 2: M2->M4->M6, vertex 3: M3->M5->M6
  • 20. typedef struct edge *edge_pointer; typedef struct edge { short int marked; int vertex1, vertex2; edge_pointer path1, path2; }; edge_pointer graph[MAX_VERTICES]; marked vertex1 vertex2 path1 path2
  • 21. Some Graph Operations  Traversal Given G=(V,E) and vertex v, find all wV, such that w connects v. – Depth First Search (DFS) preorder tree traversal – Breadth First Search (BFS) level order tree traversal  Connected Components  Spanning Trees
  • 22. Graph G and its adjacency lists depth first search: v0, v1, v3, v7, v4, v5, v2, v6 breadth first search: v0, v1, v2, v3, v4, v5, v6, v7