SlideShare une entreprise Scribd logo
1  sur  14
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].

Contenu connexe

Similaire à Graph Introduction.ppt

graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________ssuser1989da
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2showslidedump
 
Introduction to Graphs
Introduction to GraphsIntroduction to Graphs
Introduction to GraphsFulvio Corno
 
Tn 110 lecture 8
Tn 110 lecture 8Tn 110 lecture 8
Tn 110 lecture 8ITNet
 
Chapter 5 Graphs (1).ppt
Chapter 5 Graphs (1).pptChapter 5 Graphs (1).ppt
Chapter 5 Graphs (1).pptishan743441
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptxARVIND SARDAR
 
lec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.pptlec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.pptTalhaFarooqui12
 
Data structure graphs
Data structure  graphsData structure  graphs
Data structure graphsUma mohan
 
1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptx1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptxswapnilbs2728
 
Skiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strcturesSkiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strctureszukun
 
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.pdfChristianKapsales1
 

Similaire à Graph Introduction.ppt (20)

graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Introduction to Graphs
Introduction to GraphsIntroduction to Graphs
Introduction to Graphs
 
Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
 
Tn 110 lecture 8
Tn 110 lecture 8Tn 110 lecture 8
Tn 110 lecture 8
 
Chapter 5 Graphs (1).ppt
Chapter 5 Graphs (1).pptChapter 5 Graphs (1).ppt
Chapter 5 Graphs (1).ppt
 
graph ASS (1).ppt
graph ASS (1).pptgraph ASS (1).ppt
graph ASS (1).ppt
 
Graphs.pdf
Graphs.pdfGraphs.pdf
Graphs.pdf
 
Basics of graph
Basics of graphBasics of graph
Basics of graph
 
graph.ppt
graph.pptgraph.ppt
graph.ppt
 
Graph therory
Graph theroryGraph therory
Graph therory
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
 
lec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.pptlec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.ppt
 
Data structure graphs
Data structure  graphsData structure  graphs
Data structure graphs
 
1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptx1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptx
 
Skiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strcturesSkiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strctures
 
05 graph
05 graph05 graph
05 graph
 
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
 

Dernier

Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...shivangimorya083
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...SUHANI PANDEY
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfadriantubila
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Delhi Call girls
 

Dernier (20)

Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
 

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].

Notes de l'éditeur

  1. 2/1/2024 11:50 AM