SlideShare a Scribd company logo
1 of 12
Download to read offline
WELCOME
Name: Dhrumil I. Panchal
Enrollment No.: 170410107053
Subject: Analysis and Design of Algorithms
Branch: Computer Engineering (B.E.)
Year: 2019-20
TOPIC
Breadth-First Search
CONTAIN
Introduction
Algorithm
Example
BFS
 Given a graph G = (V, E) and a distinguished source vertex s, breadth-
first search systematically explores the edges of G to "discover" every
vertex that is reachable from s.
 It computes the distance (smallest number of edges) from s to each
reachable vertex.
 It also produces a "breadth-first tree" with root s that contains all
reachable vertices.
 For any vertex v reachable from s, the path in the breadth-first tree
from s to v corresponds to a "shortest path" from s to v in G, that is, a
path containing the smallest number of edges.
CONTI…
The algorithm works on both directed and undirected graphs.
Breadth-first search is so named because it expands the frontier
between discovered and undiscovered vertices uniformly across
the breadth of the frontier.
That is, the algorithm discovers all vertices at distance k from s
before discovering any vertices at distance k + 1.
BFS (G, S)
for each vertex u ϵ G.V – {s}
u.color = WHITE
u.d = ∞
u.π = NIL
s.color = GRAY
s.d = 0
s. π = NIL
Q = Ø
ENQUEUE (Q, s)
BFS (G, S)
while Q != Ø
u = DEQUEUE (Q)
for each v ϵ G.adj[u]
if v.color == WHITE
v.color = GRAY
v.d = u.d + 1
v. π = u
ENQUEUE (Q, v)
u.color = BLACK
CONTI…
Breadth first search in not naturally recursive. To understand the
differences and similarities, let us first consider the non-recursive
formulation of DFS algorithm.
Let stack be a data type allowing two operations PUSH and POP.
It handles elements in LIFO odder.
The function top denotes the first element at the top of the stack.
EXAMPLE
IF NODE 1 IS STARTING POINT
REFERENCES
Inspiration from Prof. Jayna B. Shah
Notes of ADA
Textbook of ADA
Images from Google Images
Some my own Knowledge
THANK YOU

More Related Content

Similar to BFS Algorithm Explained

Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]DEEPIKA T
 
Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsSigSegVSquad
 
DFS ppt.pdf
DFS ppt.pdfDFS ppt.pdf
DFS ppt.pdfRajkk5
 
Graph Traversal Algorithm
Graph Traversal AlgorithmGraph Traversal Algorithm
Graph Traversal Algorithmjyothimonc
 
Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8Traian Rebedea
 
Technical_Seminar .pptx
Technical_Seminar .pptxTechnical_Seminar .pptx
Technical_Seminar .pptxForJunks1
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Shuvongkor Barman
 
Analysis and design of algorithms part 3
Analysis and design of algorithms part 3Analysis and design of algorithms part 3
Analysis and design of algorithms part 3Deepak John
 
Skiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchzukun
 
Informed-search TECHNIQUES IN ai ml data science
Informed-search TECHNIQUES IN ai ml data scienceInformed-search TECHNIQUES IN ai ml data science
Informed-search TECHNIQUES IN ai ml data sciencedevvpillpersonal
 
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptxRiya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptxRIYABEPARI
 

Similar to BFS Algorithm Explained (20)

Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding Algorithms
 
DFS ppt.pdf
DFS ppt.pdfDFS ppt.pdf
DFS ppt.pdf
 
Graph Traversal Algorithm
Graph Traversal AlgorithmGraph Traversal Algorithm
Graph Traversal Algorithm
 
BFS
BFSBFS
BFS
 
Chapter 23 aoa
Chapter 23 aoaChapter 23 aoa
Chapter 23 aoa
 
Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8
 
Breadth first search
Breadth first searchBreadth first search
Breadth first search
 
Graphs
GraphsGraphs
Graphs
 
Technical_Seminar .pptx
Technical_Seminar .pptxTechnical_Seminar .pptx
Technical_Seminar .pptx
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
 
Analysis and design of algorithms part 3
Analysis and design of algorithms part 3Analysis and design of algorithms part 3
Analysis and design of algorithms part 3
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Skiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first search
 
Graphs in Data Structure
Graphs in Data StructureGraphs in Data Structure
Graphs in Data Structure
 
Informed-search TECHNIQUES IN ai ml data science
Informed-search TECHNIQUES IN ai ml data scienceInformed-search TECHNIQUES IN ai ml data science
Informed-search TECHNIQUES IN ai ml data science
 
Lecture13
Lecture13Lecture13
Lecture13
 
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptxRiya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
Riya Bepari_34700122020_Artificial Intelligence_PEC-IT501B.pptx
 

More from Ashwin180668

dfs-180809142044.pdf
dfs-180809142044.pdfdfs-180809142044.pdf
dfs-180809142044.pdfAshwin180668
 
Sensor Transmitter & Its types 22.pptx
Sensor Transmitter & Its types  22.pptxSensor Transmitter & Its types  22.pptx
Sensor Transmitter & Its types 22.pptxAshwin180668
 
embeddedsystemsppt-170506195901.pdf
embeddedsystemsppt-170506195901.pdfembeddedsystemsppt-170506195901.pdf
embeddedsystemsppt-170506195901.pdfAshwin180668
 
es1-150721100817-lva1-app6891.pdf
es1-150721100817-lva1-app6891.pdfes1-150721100817-lva1-app6891.pdf
es1-150721100817-lva1-app6891.pdfAshwin180668
 
embeddedsystemspresentation-140524063909-phpapp01.pdf
embeddedsystemspresentation-140524063909-phpapp01.pdfembeddedsystemspresentation-140524063909-phpapp01.pdf
embeddedsystemspresentation-140524063909-phpapp01.pdfAshwin180668
 
embeddedsystems-100429081552-phpapp01.pdf
embeddedsystems-100429081552-phpapp01.pdfembeddedsystems-100429081552-phpapp01.pdf
embeddedsystems-100429081552-phpapp01.pdfAshwin180668
 
physics Presentation1.pptx
physics Presentation1.pptxphysics Presentation1.pptx
physics Presentation1.pptxAshwin180668
 

More from Ashwin180668 (7)

dfs-180809142044.pdf
dfs-180809142044.pdfdfs-180809142044.pdf
dfs-180809142044.pdf
 
Sensor Transmitter & Its types 22.pptx
Sensor Transmitter & Its types  22.pptxSensor Transmitter & Its types  22.pptx
Sensor Transmitter & Its types 22.pptx
 
embeddedsystemsppt-170506195901.pdf
embeddedsystemsppt-170506195901.pdfembeddedsystemsppt-170506195901.pdf
embeddedsystemsppt-170506195901.pdf
 
es1-150721100817-lva1-app6891.pdf
es1-150721100817-lva1-app6891.pdfes1-150721100817-lva1-app6891.pdf
es1-150721100817-lva1-app6891.pdf
 
embeddedsystemspresentation-140524063909-phpapp01.pdf
embeddedsystemspresentation-140524063909-phpapp01.pdfembeddedsystemspresentation-140524063909-phpapp01.pdf
embeddedsystemspresentation-140524063909-phpapp01.pdf
 
embeddedsystems-100429081552-phpapp01.pdf
embeddedsystems-100429081552-phpapp01.pdfembeddedsystems-100429081552-phpapp01.pdf
embeddedsystems-100429081552-phpapp01.pdf
 
physics Presentation1.pptx
physics Presentation1.pptxphysics Presentation1.pptx
physics Presentation1.pptx
 

Recently uploaded

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

BFS Algorithm Explained

  • 1. WELCOME Name: Dhrumil I. Panchal Enrollment No.: 170410107053 Subject: Analysis and Design of Algorithms Branch: Computer Engineering (B.E.) Year: 2019-20
  • 4. BFS  Given a graph G = (V, E) and a distinguished source vertex s, breadth- first search systematically explores the edges of G to "discover" every vertex that is reachable from s.  It computes the distance (smallest number of edges) from s to each reachable vertex.  It also produces a "breadth-first tree" with root s that contains all reachable vertices.  For any vertex v reachable from s, the path in the breadth-first tree from s to v corresponds to a "shortest path" from s to v in G, that is, a path containing the smallest number of edges.
  • 5. CONTI… The algorithm works on both directed and undirected graphs. Breadth-first search is so named because it expands the frontier between discovered and undiscovered vertices uniformly across the breadth of the frontier. That is, the algorithm discovers all vertices at distance k from s before discovering any vertices at distance k + 1.
  • 6. BFS (G, S) for each vertex u ϵ G.V – {s} u.color = WHITE u.d = ∞ u.π = NIL s.color = GRAY s.d = 0 s. π = NIL Q = Ø ENQUEUE (Q, s)
  • 7. BFS (G, S) while Q != Ø u = DEQUEUE (Q) for each v ϵ G.adj[u] if v.color == WHITE v.color = GRAY v.d = u.d + 1 v. π = u ENQUEUE (Q, v) u.color = BLACK
  • 8. CONTI… Breadth first search in not naturally recursive. To understand the differences and similarities, let us first consider the non-recursive formulation of DFS algorithm. Let stack be a data type allowing two operations PUSH and POP. It handles elements in LIFO odder. The function top denotes the first element at the top of the stack.
  • 10. IF NODE 1 IS STARTING POINT
  • 11. REFERENCES Inspiration from Prof. Jayna B. Shah Notes of ADA Textbook of ADA Images from Google Images Some my own Knowledge