SlideShare una empresa de Scribd logo
1 de 33
Graphs ,[object Object],[object Object],[object Object],[object Object],D E A C F B Vertex Edge Vertices can be considered “sites” or locations. Edges represent connections.
Applications Air flight system ,[object Object],[object Object],[object Object],[object Object],[object Object]
Another application ,[object Object],[object Object],[object Object],[object Object],[object Object]
Definition ,[object Object],[object Object],{c,f} {a,c} {a,b} {b,d} {c,d} {e,f} {b,e}
Terminology ,[object Object],[object Object],[object Object],[object Object],*Later, we will talk about “directed graphs”, where edges have direction.  This means that {v 1 ,v 2 } ≠ {v 2 ,v 1 } .  Directed graphs are drawn with arrows (called arcs) between edges.  A B This means {A,B} only, not {B,A}
Graph Representation ,[object Object],[object Object],[object Object],[object Object],[object Object]
Adjacency Matrix ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Adjacency list ,[object Object],[object Object],[object Object]
Examples 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 2 0 1 0 0 1 0 0 0 1 0 3 0 1 0 0 1 1 0 0 0 0 4 0 0 1 1 0 0 0 0 0 0 5 0 0 0 1 0 0 1 0 0 0 6 0 0 0 0 0 1 0 1 0 0 7 0 1 0 0 0 0 1 0 0 0 8 1 0 1 0 0 0 0 0 0 1 9 0 1 0 0 0 0 0 0 1 0
Examples 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 2 3 7 9 8 1 4 8 1 4 5 2 3 3 6 5 7 1 6 0 2 9 1 8
Storage of adjacency list ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Adjacency Lists vs. Matrix ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Path between vertices ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Types of paths ,[object Object],[object Object],[object Object],[object Object]
Examples ,[object Object],[object Object],[object Object],[object Object],[object Object],Are these paths? Any cycles? What is the path’s length?
Graph Traversal ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
BFS and Shortest Path Problem ,[object Object],[object Object],Consider s=vertex 1 Nodes at distance 1? 2, 3, 7, 9 Example Nodes at distance 2? 8, 6, 5, 4 Nodes at distance 3? 0 2 4 3 5 1 7 6 9 8 0 1 1 1 1 2 2 2 2 s
BSF algorithm Why use queue? Need FIFO
Example Adjacency List source Visited Table (T/F) Q =  {  } Initialize visited table (all False) Initialize Q to be empty 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F F F F F F F F F
Example Adjacency List source Visited Table (T/F) Q =  {  2  } Flag that 2 has  been visited. Place source 2 on the queue. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F T F F F F F F F
Example Adjacency List source Visited Table (T/F) Q =  {2} ->  {  8, 1, 4 } Mark neighbors as visited. Dequeue 2.  Place all  unvisited  neighbors of 2 on the queue Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F T T F T F F F T F
Example Adjacency List source Visited Table (T/F) Q =  {  8, 1, 4 } -> { 1, 4, 0, 9 }  Mark new visited Neighbors. Dequeue 8.  -- Place all unvisited neighbors of 8 on the queue. -- Notice that 2 is not placed on the queue again, it has been visited! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T F T F F F T T
Example Adjacency List source Visited Table (T/F) Q =  {  1, 4, 0, 9 } -> { 4, 0, 9, 3, 7 }  Mark new visited Neighbors. Dequeue 1.  -- Place all unvisited neighbors of 1 on the queue. -- Only nodes 3 and 7 haven’t been visited yet. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
Example Adjacency List source Visited Table (T/F) Q =  { 4, 0, 9, 3, 7 } -> { 0, 9, 3, 7 }  Dequeue 4.  -- 4 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
Example Adjacency List source Visited Table (T/F) Q =  { 0, 9, 3, 7 } -> { 9, 3, 7 }  Dequeue 0.  -- 0 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
Example Adjacency List source Visited Table (T/F) Q =  { 9, 3, 7 } -> { 3, 7 }  Dequeue 9.  -- 9 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
Example Adjacency List source Visited Table (T/F) Q =  { 3, 7 } -> { 7, 5 }  Dequeue 3.  -- place neighbor 5 on the queue. Neighbors Mark new visited Vertex 5. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T F T T T
Example Adjacency List source Visited Table (T/F) Q =  { 7, 5 } -> { 5, 6 }  Dequeue 7.  -- place neighbor 6 on the queue. Neighbors Mark new visited Vertex 6. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
Example Adjacency List source Visited Table (T/F) Q =  { 5, 6} -> { 6 }  Dequeue 5.  -- no unvisited neighbors of 5. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
Example Adjacency List source Visited Table (T/F) Q =  { 6 } -> {  }  Dequeue 6.  -- no unvisited neighbors of 6. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
Example Adjacency List source Visited Table (T/F) Q =  {  }  STOP!!!  Q is empty!!! What did we discover? Look at “visited” tables. There exists a path from source vertex 2 to all vertices in the graph. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
Time Complexity of BFS (Using adjacency list) ,[object Object],[object Object],Each vertex will enter Q at most once. Each iteration takes time proportional to deg(v) + 1  (the number 1 is to include the case where deg(v) = 0). O(n + m)
Running time ,[object Object],[object Object],[object Object],O(  Σ vertex  v  (deg(v)  +  1) )  =  O(n+m) Σ vertex  v  deg(v)   =   2m

Más contenido relacionado

La actualidad más candente (16)

Graph Theory Introduction
Graph Theory IntroductionGraph Theory Introduction
Graph Theory Introduction
 
Graph terminologies & special type graphs
Graph terminologies & special type graphsGraph terminologies & special type graphs
Graph terminologies & special type graphs
 
Basics on Graph Theory
Basics on Graph TheoryBasics on Graph Theory
Basics on Graph Theory
 
graph theory
graph theory graph theory
graph theory
 
Graph theory
Graph theoryGraph theory
Graph theory
 
graph theory
graph theorygraph theory
graph theory
 
introduction to graph theory
introduction to graph theoryintroduction to graph theory
introduction to graph theory
 
Graph theory
Graph  theoryGraph  theory
Graph theory
 
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
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Applications of graphs
Applications of graphsApplications of graphs
Applications of graphs
 
Graphs Algorithms
Graphs AlgorithmsGraphs Algorithms
Graphs Algorithms
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Presentation on graphs
Presentation on graphsPresentation on graphs
Presentation on graphs
 
Trees and graphs
Trees and graphsTrees and graphs
Trees and graphs
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
 

Destacado

Vertex edge graphs
Vertex edge graphsVertex edge graphs
Vertex edge graphs
emteacher
 
Test Case Management with MTM 2013
Test Case Management with MTM 2013Test Case Management with MTM 2013
Test Case Management with MTM 2013
Raluca Suditu
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
Kumar
 
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
 
Graph representation
Graph representationGraph representation
Graph representation
Tech_MX
 

Destacado (14)

Vertex Edge Graphs
Vertex Edge GraphsVertex Edge Graphs
Vertex Edge Graphs
 
Vertex edge graphs
Vertex edge graphsVertex edge graphs
Vertex edge graphs
 
Test cases
Test casesTest cases
Test cases
 
Test Case Management with MTM 2013
Test Case Management with MTM 2013Test Case Management with MTM 2013
Test Case Management with MTM 2013
 
Software Verification, Validation and Testing
Software Verification, Validation and TestingSoftware Verification, Validation and Testing
Software Verification, Validation and Testing
 
Test design techniques: Structured and Experienced-based techniques
Test design techniques: Structured and Experienced-based techniquesTest design techniques: Structured and Experienced-based techniques
Test design techniques: Structured and Experienced-based techniques
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
Blackbox
BlackboxBlackbox
Blackbox
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
 
Graph representation
Graph representationGraph representation
Graph representation
 
Lecture8 data structure(graph)
Lecture8 data structure(graph)Lecture8 data structure(graph)
Lecture8 data structure(graph)
 
The Graph Traversal Programming Pattern
The Graph Traversal Programming PatternThe Graph Traversal Programming Pattern
The Graph Traversal Programming Pattern
 

Similar a Graphs

Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
Victor Palmar
 
lecture 17
lecture 17lecture 17
lecture 17
sajinsc
 

Similar a Graphs (20)

Week12 graph
Week12   graph Week12   graph
Week12 graph
 
Graps 2
Graps 2Graps 2
Graps 2
 
Breadth first search
Breadth first searchBreadth first search
Breadth first search
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
Graphs
GraphsGraphs
Graphs
 
Graph
GraphGraph
Graph
 
Temporal graph
Temporal graphTemporal graph
Temporal graph
 
lec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.pptlec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.ppt
 
lecture 17
lecture 17lecture 17
lecture 17
 
Dijkstra
DijkstraDijkstra
Dijkstra
 
d
dd
d
 
graph.pptx
graph.pptxgraph.pptx
graph.pptx
 
Algorithms Design Exam Help
Algorithms Design Exam HelpAlgorithms Design Exam Help
Algorithms Design Exam Help
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
Graph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptxGraph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptx
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
 
Topological sort
Topological sortTopological sort
Topological sort
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
 
graph ASS (1).ppt
graph ASS (1).pptgraph ASS (1).ppt
graph ASS (1).ppt
 

Más de Saurabh Mishra (7)

Sorting2
Sorting2Sorting2
Sorting2
 
Sorting
SortingSorting
Sorting
 
Searching
SearchingSearching
Searching
 
Presentation1
Presentation1Presentation1
Presentation1
 
Data structures
Data structuresData structures
Data structures
 
Trees
TreesTrees
Trees
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Graphs

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. Examples 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 2 0 1 0 0 1 0 0 0 1 0 3 0 1 0 0 1 1 0 0 0 0 4 0 0 1 1 0 0 0 0 0 0 5 0 0 0 1 0 0 1 0 0 0 6 0 0 0 0 0 1 0 1 0 0 7 0 1 0 0 0 0 1 0 0 0 8 1 0 1 0 0 0 0 0 0 1 9 0 1 0 0 0 0 0 0 1 0
  • 10. Examples 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 2 3 7 9 8 1 4 8 1 4 5 2 3 3 6 5 7 1 6 0 2 9 1 8
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18. BSF algorithm Why use queue? Need FIFO
  • 19. Example Adjacency List source Visited Table (T/F) Q = { } Initialize visited table (all False) Initialize Q to be empty 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F F F F F F F F F
  • 20. Example Adjacency List source Visited Table (T/F) Q = { 2 } Flag that 2 has been visited. Place source 2 on the queue. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F T F F F F F F F
  • 21. Example Adjacency List source Visited Table (T/F) Q = {2} -> { 8, 1, 4 } Mark neighbors as visited. Dequeue 2. Place all unvisited neighbors of 2 on the queue Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F T T F T F F F T F
  • 22. Example Adjacency List source Visited Table (T/F) Q = { 8, 1, 4 } -> { 1, 4, 0, 9 } Mark new visited Neighbors. Dequeue 8. -- Place all unvisited neighbors of 8 on the queue. -- Notice that 2 is not placed on the queue again, it has been visited! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T F T F F F T T
  • 23. Example Adjacency List source Visited Table (T/F) Q = { 1, 4, 0, 9 } -> { 4, 0, 9, 3, 7 } Mark new visited Neighbors. Dequeue 1. -- Place all unvisited neighbors of 1 on the queue. -- Only nodes 3 and 7 haven’t been visited yet. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
  • 24. Example Adjacency List source Visited Table (T/F) Q = { 4, 0, 9, 3, 7 } -> { 0, 9, 3, 7 } Dequeue 4. -- 4 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
  • 25. Example Adjacency List source Visited Table (T/F) Q = { 0, 9, 3, 7 } -> { 9, 3, 7 } Dequeue 0. -- 0 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
  • 26. Example Adjacency List source Visited Table (T/F) Q = { 9, 3, 7 } -> { 3, 7 } Dequeue 9. -- 9 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
  • 27. Example Adjacency List source Visited Table (T/F) Q = { 3, 7 } -> { 7, 5 } Dequeue 3. -- place neighbor 5 on the queue. Neighbors Mark new visited Vertex 5. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T F T T T
  • 28. Example Adjacency List source Visited Table (T/F) Q = { 7, 5 } -> { 5, 6 } Dequeue 7. -- place neighbor 6 on the queue. Neighbors Mark new visited Vertex 6. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
  • 29. Example Adjacency List source Visited Table (T/F) Q = { 5, 6} -> { 6 } Dequeue 5. -- no unvisited neighbors of 5. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
  • 30. Example Adjacency List source Visited Table (T/F) Q = { 6 } -> { } Dequeue 6. -- no unvisited neighbors of 6. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
  • 31. Example Adjacency List source Visited Table (T/F) Q = { } STOP!!! Q is empty!!! What did we discover? Look at “visited” tables. There exists a path from source vertex 2 to all vertices in the graph. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
  • 32.
  • 33.