SlideShare a Scribd company logo
Graphs 1
Graphs
hierarchical
(1 to many)
graph (many to many)
first ith last
sequence/linear (1 to 1)
Graphs 2
What is a Graph?
A graph is a pair (V, E), where
 V is a set of nodes, called vertices
 E is a collection of pairs of vertices, called edges
V(G) and E(G) represent the sets of vertices and edges of G,
respectively
Example:
A tree is a special type of graph!
a b
c
d e
V= {a, b, c, d, e}
E= {(a,b), (a,c), (a,d),
(b,e), (c,d), (c,e), (d,e)}
Graphs 3
John
David
Paul
brown.edu
cox.net
cs.brown.edu
att.net
qwest.net
math.brown.edu
cslab1b
cslab1a
Applications
Electronic circuits
 Printed circuit board
 Integrated circuit
Transportation networks
 Highway network
 Flight network
Computer networks
 Local area network
 Internet
 Web
Databases
 Entity-relationship diagram
Graphs 4
What can we do with graphs?
Find a path from one place to another
Find the shortest path from one place to another
Determine connectivity
Find the “weakest link” (min cut)
• check amount of redundancy in case of failures
Find the amount of flow that will go through them
Graphs 5
Edge and Graph Types
Directed edge
 ordered pair of vertices (u,v)
 first vertex u is the origin
 second vertex v is the destination
Undirected edge
 unordered pair of vertices (u,v)
Directed graph (Digraph)
 all the edges are directed
 e.g., route network
Undirected graph
 all the edges are undirected
 e.g., flight network
Mixed graph
 some edges are undirected and
some edges are directed
 e.g., a graph modeling a city map
a b
a b
a b
c
d e
Directed edge
Undirected edge
Mixed graph
Graphs 6
Terminology
End vertices (or endpoints) of
an edge
 u and v are the endpoints of a
Edges incident to a vertex
 a, d, and b are incident to v
Adjacent vertices
 u and v are adjacent
Degree of a vertex
 x has degree 5
Parallel edges
 h and i are parallel edges
Self-loop
 j is a self-loop
x
u
v
w
z
y
a
c
b
e
d
f
g
h
i
j
Graphs 7
Terminology (cont.)
Outgoing edges of a vertex
 (a, b) and (a, c) are outgoing
edges of vertex a
Incoming edges of a vertex
 (b, c), (d, c) and (a, c) are
incoming edges of vertex c
In-degree of a vertex
 c has in-degree 3
 b has in-degree 1
Out-degree of a vertex
 a has out-degree 2
 b has out-degree 1
a
b d
c
Graphs 8
Graph Representation
For graphs to be computationally useful, they
have to be conveniently represented in
programs
There are two computer representations of
graphs:
 Adjacency matrix representation
 Adjacency lists representation
Graphs 9
Adjacency Matrix Representation
Assume V = {1, 2, …, n}
An adjacency matrix represents the graph as a n x n
matrix A:
 A[i, j] = 1 if edge (i, j)  E (or weight of edge)
= 0 if edge (i, j)  E
1
2 4
3
a
d
b c
A 1 2 3 4
1 0 1 1 0
2 0 0 1 0
3 0 0 0 0
4 0 0 1 0
Graphs 10
Adjacency Matrix Representation
Undirected Graph
Directed Graph
The adjacency matrix for an undirected graph is symmetric;
the adjacency matrix for a digraph need not be symmetric
Graphs 11
Adjacency Matrix Representation
Pros:
 Simple to implement
 Easy and fast to tell if a pair (i, j) is an edge:
simply check if A[i, j] is 1 or 0
 Can be very efficient for small graphs
Cons:
 No matter how few edges the graph has, the
matrix takes O(n2) in memory
Graphs 12
Adjacency Lists Representation
A graph is represented by a one-dimensional array L of
linked lists, where
 L[i] is the linked list containing all the nodes adjacent
to node i.
 The nodes in the list L[i] are in no particular order
Example:
 Adj[1] = {2,3}
 Adj[2] = {3}
 Adj[3] = {}
 Adj[4] = {3}
1
2 4
3
Graphs 13
Adjacency Lists Representation
Undirected Graph
Directed Graph
Graphs 14
Adjacency Lists Representation
Pros:
 Saves on space (memory): the representation
takes O(|V|+|E|) memory.
 Good for large, sparse graphs (e.g., planar maps)
Cons:
 It can take up to O(n) time to determine if a pair
of nodes (i, j) is an edge: one would have to
search the linked list L[i], which takes time
proportional to the length of L[i].
Ad

More Related Content

Similar to Graph Introduction.ppt (20)

Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
Victor Palmar
 
graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________
ssuser1989da
 
GraphGraph data structureGraph data structure.ppt
GraphGraph data structureGraph data structure.pptGraphGraph data structureGraph data structure.ppt
GraphGraph data structureGraph data structure.ppt
jamnona
 
GraphGraph data structureGraph data structure.ppt
GraphGraph data structureGraph data structure.pptGraphGraph data structureGraph data structure.ppt
GraphGraph data structureGraph data structure.ppt
jamnona
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
showslidedump
 
Graph theory
Graph theoryGraph theory
Graph theory
AparnaKumari31
 
Introduction to Graphs
Introduction to GraphsIntroduction to Graphs
Introduction to Graphs
Fulvio Corno
 
Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
satvikkushwaha1
 
Tn 110 lecture 8
Tn 110 lecture 8Tn 110 lecture 8
Tn 110 lecture 8
ITNet
 
Chapter 5 Graphs (1).ppt
Chapter 5 Graphs (1).pptChapter 5 Graphs (1).ppt
Chapter 5 Graphs (1).ppt
ishan743441
 
graph ASS (1).ppt
graph ASS (1).pptgraph ASS (1).ppt
graph ASS (1).ppt
ARVIND SARDAR
 
Graphs.pdf
Graphs.pdfGraphs.pdf
Graphs.pdf
pubggaming58982
 
Graph Theory in Theoretical computer science
Graph Theory in Theoretical computer scienceGraph Theory in Theoretical computer science
Graph Theory in Theoretical computer science
Ahmad177077
 
Basics of graph
Basics of graphBasics of graph
Basics of graph
Khaled Sany
 
graphass1-23022111180722548-1ba6b00a.ppt
graphass1-23022111180722548-1ba6b00a.pptgraphass1-23022111180722548-1ba6b00a.ppt
graphass1-23022111180722548-1ba6b00a.ppt
ssuser7b9bda1
 
graph.ppt
graph.pptgraph.ppt
graph.ppt
RakeshPandey951330
 
Graph therory
Graph theroryGraph therory
Graph therory
mohanrathod18
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
ARVIND SARDAR
 
lec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.pptlec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.ppt
TalhaFarooqui12
 
Data structure graphs
Data structure  graphsData structure  graphs
Data structure graphs
Uma mohan
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
Victor Palmar
 
graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________
ssuser1989da
 
GraphGraph data structureGraph data structure.ppt
GraphGraph data structureGraph data structure.pptGraphGraph data structureGraph data structure.ppt
GraphGraph data structureGraph data structure.ppt
jamnona
 
GraphGraph data structureGraph data structure.ppt
GraphGraph data structureGraph data structure.pptGraphGraph data structureGraph data structure.ppt
GraphGraph data structureGraph data structure.ppt
jamnona
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
showslidedump
 
Introduction to Graphs
Introduction to GraphsIntroduction to Graphs
Introduction to Graphs
Fulvio Corno
 
Tn 110 lecture 8
Tn 110 lecture 8Tn 110 lecture 8
Tn 110 lecture 8
ITNet
 
Chapter 5 Graphs (1).ppt
Chapter 5 Graphs (1).pptChapter 5 Graphs (1).ppt
Chapter 5 Graphs (1).ppt
ishan743441
 
Graph Theory in Theoretical computer science
Graph Theory in Theoretical computer scienceGraph Theory in Theoretical computer science
Graph Theory in Theoretical computer science
Ahmad177077
 
graphass1-23022111180722548-1ba6b00a.ppt
graphass1-23022111180722548-1ba6b00a.pptgraphass1-23022111180722548-1ba6b00a.ppt
graphass1-23022111180722548-1ba6b00a.ppt
ssuser7b9bda1
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
ARVIND SARDAR
 
lec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.pptlec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.ppt
TalhaFarooqui12
 
Data structure graphs
Data structure  graphsData structure  graphs
Data structure graphs
Uma mohan
 

Recently uploaded (20)

chapter 4 Variability statistical research .pptx
chapter 4 Variability statistical research .pptxchapter 4 Variability statistical research .pptx
chapter 4 Variability statistical research .pptx
justinebandajbn
 
Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..
yuvarajreddy2002
 
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjks
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjksPpt. Nikhil.pptxnshwuudgcudisisshvehsjks
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjks
panchariyasahil
 
Digilocker under workingProcess Flow.pptx
Digilocker  under workingProcess Flow.pptxDigilocker  under workingProcess Flow.pptx
Digilocker under workingProcess Flow.pptx
satnamsadguru491
 
Day 1 - Lab 1 Reconnaissance Scanning with NMAP, Vulnerability Assessment wit...
Day 1 - Lab 1 Reconnaissance Scanning with NMAP, Vulnerability Assessment wit...Day 1 - Lab 1 Reconnaissance Scanning with NMAP, Vulnerability Assessment wit...
Day 1 - Lab 1 Reconnaissance Scanning with NMAP, Vulnerability Assessment wit...
Abodahab
 
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.pptJust-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
ssuser5f8f49
 
FPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptxFPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptx
ssuser4ef83d
 
Deloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit contextDeloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit context
Process mining Evangelist
 
Classification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptxClassification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptx
wencyjorda88
 
Geometry maths presentation for begginers
Geometry maths presentation for begginersGeometry maths presentation for begginers
Geometry maths presentation for begginers
zrjacob283
 
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
ThanushsaranS
 
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptxmd-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
fatimalazaar2004
 
LLM finetuning for multiple choice google bert
LLM finetuning for multiple choice google bertLLM finetuning for multiple choice google bert
LLM finetuning for multiple choice google bert
ChadapornK
 
Molecular methods diagnostic and monitoring of infection - Repaired.pptx
Molecular methods diagnostic and monitoring of infection  -  Repaired.pptxMolecular methods diagnostic and monitoring of infection  -  Repaired.pptx
Molecular methods diagnostic and monitoring of infection - Repaired.pptx
7tzn7x5kky
 
Flip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptxFlip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptx
mubashirkhan45461
 
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
James Francis Paradigm Asset Management
 
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnTemplate_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
cegiver630
 
Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...
Pixellion
 
VKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptxVKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptx
Vinod Srivastava
 
Principles of information security Chapter 5.ppt
Principles of information security Chapter 5.pptPrinciples of information security Chapter 5.ppt
Principles of information security Chapter 5.ppt
EstherBaguma
 
chapter 4 Variability statistical research .pptx
chapter 4 Variability statistical research .pptxchapter 4 Variability statistical research .pptx
chapter 4 Variability statistical research .pptx
justinebandajbn
 
Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..
yuvarajreddy2002
 
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjks
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjksPpt. Nikhil.pptxnshwuudgcudisisshvehsjks
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjks
panchariyasahil
 
Digilocker under workingProcess Flow.pptx
Digilocker  under workingProcess Flow.pptxDigilocker  under workingProcess Flow.pptx
Digilocker under workingProcess Flow.pptx
satnamsadguru491
 
Day 1 - Lab 1 Reconnaissance Scanning with NMAP, Vulnerability Assessment wit...
Day 1 - Lab 1 Reconnaissance Scanning with NMAP, Vulnerability Assessment wit...Day 1 - Lab 1 Reconnaissance Scanning with NMAP, Vulnerability Assessment wit...
Day 1 - Lab 1 Reconnaissance Scanning with NMAP, Vulnerability Assessment wit...
Abodahab
 
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.pptJust-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
ssuser5f8f49
 
FPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptxFPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptx
ssuser4ef83d
 
Deloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit contextDeloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit context
Process mining Evangelist
 
Classification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptxClassification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptx
wencyjorda88
 
Geometry maths presentation for begginers
Geometry maths presentation for begginersGeometry maths presentation for begginers
Geometry maths presentation for begginers
zrjacob283
 
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
ThanushsaranS
 
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptxmd-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
fatimalazaar2004
 
LLM finetuning for multiple choice google bert
LLM finetuning for multiple choice google bertLLM finetuning for multiple choice google bert
LLM finetuning for multiple choice google bert
ChadapornK
 
Molecular methods diagnostic and monitoring of infection - Repaired.pptx
Molecular methods diagnostic and monitoring of infection  -  Repaired.pptxMolecular methods diagnostic and monitoring of infection  -  Repaired.pptx
Molecular methods diagnostic and monitoring of infection - Repaired.pptx
7tzn7x5kky
 
Flip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptxFlip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptx
mubashirkhan45461
 
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
James Francis Paradigm Asset Management
 
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnTemplate_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
cegiver630
 
Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...
Pixellion
 
VKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptxVKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptx
Vinod Srivastava
 
Principles of information security Chapter 5.ppt
Principles of information security Chapter 5.pptPrinciples of information security Chapter 5.ppt
Principles of information security Chapter 5.ppt
EstherBaguma
 
Ad

Graph Introduction.ppt

  • 1. Graphs 1 Graphs hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1)
  • 2. Graphs 2 What is a Graph? A graph is a pair (V, E), where  V is a set of nodes, called vertices  E is a collection of pairs of vertices, called edges V(G) and E(G) represent the sets of vertices and edges of G, respectively Example: A tree is a special type of graph! a b c d e V= {a, b, c, d, e} E= {(a,b), (a,c), (a,d), (b,e), (c,d), (c,e), (d,e)}
  • 3. Graphs 3 John David Paul brown.edu cox.net cs.brown.edu att.net qwest.net math.brown.edu cslab1b cslab1a Applications Electronic circuits  Printed circuit board  Integrated circuit Transportation networks  Highway network  Flight network Computer networks  Local area network  Internet  Web Databases  Entity-relationship diagram
  • 4. Graphs 4 What can we do with graphs? Find a path from one place to another Find the shortest path from one place to another Determine connectivity Find the “weakest link” (min cut) • check amount of redundancy in case of failures Find the amount of flow that will go through them
  • 5. Graphs 5 Edge and Graph Types Directed edge  ordered pair of vertices (u,v)  first vertex u is the origin  second vertex v is the destination Undirected edge  unordered pair of vertices (u,v) Directed graph (Digraph)  all the edges are directed  e.g., route network Undirected graph  all the edges are undirected  e.g., flight network Mixed graph  some edges are undirected and some edges are directed  e.g., a graph modeling a city map a b a b a b c d e Directed edge Undirected edge Mixed graph
  • 6. Graphs 6 Terminology End vertices (or endpoints) of an edge  u and v are the endpoints of a Edges incident to a vertex  a, d, and b are incident to v Adjacent vertices  u and v are adjacent Degree of a vertex  x has degree 5 Parallel edges  h and i are parallel edges Self-loop  j is a self-loop x u v w z y a c b e d f g h i j
  • 7. Graphs 7 Terminology (cont.) Outgoing edges of a vertex  (a, b) and (a, c) are outgoing edges of vertex a Incoming edges of a vertex  (b, c), (d, c) and (a, c) are incoming edges of vertex c In-degree of a vertex  c has in-degree 3  b has in-degree 1 Out-degree of a vertex  a has out-degree 2  b has out-degree 1 a b d c
  • 8. Graphs 8 Graph Representation For graphs to be computationally useful, they have to be conveniently represented in programs There are two computer representations of graphs:  Adjacency matrix representation  Adjacency lists representation
  • 9. Graphs 9 Adjacency Matrix Representation Assume V = {1, 2, …, n} An adjacency matrix represents the graph as a n x n matrix A:  A[i, j] = 1 if edge (i, j)  E (or weight of edge) = 0 if edge (i, j)  E 1 2 4 3 a d b c A 1 2 3 4 1 0 1 1 0 2 0 0 1 0 3 0 0 0 0 4 0 0 1 0
  • 10. Graphs 10 Adjacency Matrix Representation Undirected Graph Directed Graph The adjacency matrix for an undirected graph is symmetric; the adjacency matrix for a digraph need not be symmetric
  • 11. Graphs 11 Adjacency Matrix Representation Pros:  Simple to implement  Easy and fast to tell if a pair (i, j) is an edge: simply check if A[i, j] is 1 or 0  Can be very efficient for small graphs Cons:  No matter how few edges the graph has, the matrix takes O(n2) in memory
  • 12. Graphs 12 Adjacency Lists Representation A graph is represented by a one-dimensional array L of linked lists, where  L[i] is the linked list containing all the nodes adjacent to node i.  The nodes in the list L[i] are in no particular order Example:  Adj[1] = {2,3}  Adj[2] = {3}  Adj[3] = {}  Adj[4] = {3} 1 2 4 3
  • 13. Graphs 13 Adjacency Lists Representation Undirected Graph Directed Graph
  • 14. Graphs 14 Adjacency Lists Representation Pros:  Saves on space (memory): the representation takes O(|V|+|E|) memory.  Good for large, sparse graphs (e.g., planar maps) Cons:  It can take up to O(n) time to determine if a pair of nodes (i, j) is an edge: one would have to search the linked list L[i], which takes time proportional to the length of L[i].

Editor's Notes

  • #2: 2/1/2024 11:50 AM