SlideShare a Scribd company logo
10
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
Graph g:
myG.txt
6
8
0 5
2 4
2 3
1 2
0 1
3 4
3 5
0 2
V
E
Adjacency lists
adj[]
0
1
2
3
4
5
2
3
3
0
5
1
0
3
1
2
4
2
2
0
5
0
1
2
5
3 4
4
Challenge: build adjacency lists – Job done
11
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
add 0 to queue:
myG.txt
6
8
0 5
2 4
2 3
1 2
0 1
3 4
3 5
0 2
V
E
Adjacency lists
adj[]
0
1
2
3
4
5
2
3
3
0
5
1
0
3
1
2
4
2
2
0
5
0
1
2
5
3 4
4
12
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
add 0 to queue:
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 - -
2 - -
3 - -
4 - -
5 - -
queue
0
13
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 0: check2, check 1 and check 5
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 - -
2 0 1
3 - -
4 - -
5 - -
queue
0
2 1 5adj[0]
14
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 0: check2, check 1 and check 5
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 - -
2 0 1
3 - -
4 - -
5 - -
queue
2 1 5adj[0]
15
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 0: check2, check 1 and check 5
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 - -
2 0 1
3 - -
4 - -
5 - -
queue
2
2 1 5adj[0]
16
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 0: check2, check 1 and check 5
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 - -
2 0 1
3 - -
4 - -
5 - -
queue
2
2 1 5adj[0]
17
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 0: check2, check 1 and check 5
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 - -
4 - -
5 - -
queue
1
2
2 1 5adj[0]
18
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 0: check2, check 1 and check 5
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 - -
4 - -
5 - -
queue
1
2
2 1 5adj[0]
19
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 0: check2, check 1 and check 5
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 - -
4 - -
5 0 1
queue
5
1
2
2 1 5adj[0]
20
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
0 done
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 - -
4 - -
5 0 1
queue
5
1
2
2 1 5adj[0]
21
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 2:
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 - -
4 - -
5 0 1
queue
5
1
2
22
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 2: check 0, check 1, check 3 and check 4
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 - -
4 - -
5 0 1
queue
5
1
adj[2] 0 1 3 4
23
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 2: check 0, check 1, check 3 and check 4
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 - -
4 - -
5 0 1
queue
5
1
adj[2] 0 1 3 4
24
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 2: check 0, check 1, check 3 and check 4
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 - -
5 0 1
queue
3
5
1
adj[2] 0 1 3 4
25
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 2: check 0, check 1, check 3 and check 4
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 - -
5 0 1
queue
3
5
1
adj[2] 0 1 3 4
26
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 2: check 0, check 1, check 3 and check 4
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 - -
5 0 1
queue
4
3
5
1
adj[2] 0 1 3 4
27
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
2 done
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
3
5
1
adj[2] 0 1 3 4
28
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 1
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
3
5
1
29
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 1
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
3
5
30
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 1: check 0, and check 2
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
3
5
adj[1] 0 2
31
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 1: check 0, and check 2
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
3
5
adj[1] 0 2
32
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 1: check 0, and check 2
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
3
5
adj[1] 0 2
33
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
1 done
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
3
5
adj[1] 0 2
34
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 5: check 3 and check 0
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
3
5
adj[5] 3 0
35
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
5 done
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
3
adj[5] 3 0
36
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 3: Check 5, Check 4, and Check 2
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
3
adj[3] 5 4 2
37
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 3:
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
3
38
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 3: Check 5, Check 4, and Check 2
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
adj[3] 5 4 2
39
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
3 done
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
adj[3] 5 4 2
40
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 4
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
4
41
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
dequeue 4: Check 3 and Check 2
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
adj[4] 3 2
42
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
4 done
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1
queue
43
Breadth-first search demo
Repeat until queue is empty:
• Remove vertex v from queue.
• Add to queue all unmarked vertices adjacent to v and mark them.
done
0
1
2
5
3 4
v edgeTo[v] distTo[]
0 - 0
1 0 1
2 0 1
3 2 2
4 2 2
5 0 1

More Related Content

Recently uploaded

Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
Kamal Acharya
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
AbrahamGadissa
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
Kamal Acharya
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 

Recently uploaded (20)

KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringKIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
 
fluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerfluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answer
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdf
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
 
fundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projectionfundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projection
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Graph bfs

  • 1. 10 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. Graph g: myG.txt 6 8 0 5 2 4 2 3 1 2 0 1 3 4 3 5 0 2 V E Adjacency lists adj[] 0 1 2 3 4 5 2 3 3 0 5 1 0 3 1 2 4 2 2 0 5 0 1 2 5 3 4 4 Challenge: build adjacency lists – Job done
  • 2. 11 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. add 0 to queue: myG.txt 6 8 0 5 2 4 2 3 1 2 0 1 3 4 3 5 0 2 V E Adjacency lists adj[] 0 1 2 3 4 5 2 3 3 0 5 1 0 3 1 2 4 2 2 0 5 0 1 2 5 3 4 4
  • 3. 12 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. add 0 to queue: 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 - - 2 - - 3 - - 4 - - 5 - - queue 0
  • 4. 13 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 0: check2, check 1 and check 5 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 - - 2 0 1 3 - - 4 - - 5 - - queue 0 2 1 5adj[0]
  • 5. 14 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 0: check2, check 1 and check 5 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 - - 2 0 1 3 - - 4 - - 5 - - queue 2 1 5adj[0]
  • 6. 15 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 0: check2, check 1 and check 5 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 - - 2 0 1 3 - - 4 - - 5 - - queue 2 2 1 5adj[0]
  • 7. 16 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 0: check2, check 1 and check 5 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 - - 2 0 1 3 - - 4 - - 5 - - queue 2 2 1 5adj[0]
  • 8. 17 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 0: check2, check 1 and check 5 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 - - 4 - - 5 - - queue 1 2 2 1 5adj[0]
  • 9. 18 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 0: check2, check 1 and check 5 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 - - 4 - - 5 - - queue 1 2 2 1 5adj[0]
  • 10. 19 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 0: check2, check 1 and check 5 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 - - 4 - - 5 0 1 queue 5 1 2 2 1 5adj[0]
  • 11. 20 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. 0 done 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 - - 4 - - 5 0 1 queue 5 1 2 2 1 5adj[0]
  • 12. 21 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 2: 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 - - 4 - - 5 0 1 queue 5 1 2
  • 13. 22 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 2: check 0, check 1, check 3 and check 4 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 - - 4 - - 5 0 1 queue 5 1 adj[2] 0 1 3 4
  • 14. 23 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 2: check 0, check 1, check 3 and check 4 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 - - 4 - - 5 0 1 queue 5 1 adj[2] 0 1 3 4
  • 15. 24 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 2: check 0, check 1, check 3 and check 4 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 - - 5 0 1 queue 3 5 1 adj[2] 0 1 3 4
  • 16. 25 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 2: check 0, check 1, check 3 and check 4 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 - - 5 0 1 queue 3 5 1 adj[2] 0 1 3 4
  • 17. 26 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 2: check 0, check 1, check 3 and check 4 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 - - 5 0 1 queue 4 3 5 1 adj[2] 0 1 3 4
  • 18. 27 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. 2 done 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 3 5 1 adj[2] 0 1 3 4
  • 19. 28 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 1 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 3 5 1
  • 20. 29 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 1 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 3 5
  • 21. 30 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 1: check 0, and check 2 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 3 5 adj[1] 0 2
  • 22. 31 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 1: check 0, and check 2 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 3 5 adj[1] 0 2
  • 23. 32 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 1: check 0, and check 2 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 3 5 adj[1] 0 2
  • 24. 33 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. 1 done 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 3 5 adj[1] 0 2
  • 25. 34 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 5: check 3 and check 0 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 3 5 adj[5] 3 0
  • 26. 35 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. 5 done 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 3 adj[5] 3 0
  • 27. 36 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 3: Check 5, Check 4, and Check 2 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 3 adj[3] 5 4 2
  • 28. 37 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 3: 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 3
  • 29. 38 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 3: Check 5, Check 4, and Check 2 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 adj[3] 5 4 2
  • 30. 39 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. 3 done 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4 adj[3] 5 4 2
  • 31. 40 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 4 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue 4
  • 32. 41 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. dequeue 4: Check 3 and Check 2 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue adj[4] 3 2
  • 33. 42 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. 4 done 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1 queue
  • 34. 43 Breadth-first search demo Repeat until queue is empty: • Remove vertex v from queue. • Add to queue all unmarked vertices adjacent to v and mark them. done 0 1 2 5 3 4 v edgeTo[v] distTo[] 0 - 0 1 0 1 2 0 1 3 2 2 4 2 2 5 0 1