SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

What's hot (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
 

Viewers also liked

Vertex Edge Graphs
Vertex Edge GraphsVertex Edge Graphs
Vertex Edge Graphsmrwilliams
 
Vertex edge graphs
Vertex edge graphsVertex edge graphs
Vertex edge graphsemteacher
 
Test Case Management with MTM 2013
Test Case Management with MTM 2013Test Case Management with MTM 2013
Test Case Management with MTM 2013Raluca Suditu
 
Software Verification, Validation and Testing
Software Verification, Validation and TestingSoftware Verification, Validation and Testing
Software Verification, Validation and TestingDr Sukhpal Singh Gill
 
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 techniquesKhuong Nguyen
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphsKumar
 
Graph data structure
Graph data structureGraph data structure
Graph data structureTech_MX
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of GraphAbhishek Pachisia
 
Graph representation
Graph representationGraph representation
Graph representationTech_MX
 
The Graph Traversal Programming Pattern
The Graph Traversal Programming PatternThe Graph Traversal Programming Pattern
The Graph Traversal Programming PatternMarko Rodriguez
 

Viewers also liked (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 to 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
 

More from 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
 

Recently uploaded

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

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.