SlideShare une entreprise Scribd logo
1  sur  49
Welcome
EVERYONE
1
Dhaka International University
2
Presentation on
Presented To
Mr. Tahzib Ul Islam
Assistant Professor
Department of CSE
Dhaka International University
Presented By
Group: Quiet Fools
Name, Roll
Shuvongkor Barman (38)
Abdullah Al-Helal (33)
Subarna (17)
CSE-E59-7th
3
1. Introduction
2.What is BFS?
3. Necessary Terms
4. BFS Illustration with Example
5. Pseudocode of BFS
6. BFS Program (Java) and Output
7.Algorithm with Example
8. Application of BFS?
9.Time and Space Complexity
10. Conclusion
11. Questions
BFS and its application in finding connected
components of graphs were originally invented
in 1945 by Konrad Zuse.
He was a German Civil Engineer, inventor and
computer pioneer. His greatest achievement
was the world's first programmable computer.
4
Inventor of BFS
Konrad Zuse
5
Breadth-first search (BFS) is an algorithm for
traversing or searching Tree or Graph data structures.
It starts at the tree root or some arbitrary node of a graph,
sometimes referred to as a 'search key’ and explores all of
the neighbor nodes at the present depth prior to moving on
to the nodes at the next depth level.
What is Breadth First Search (BFS)?
 A Graph G=(V, E) consists a set of vertices, V, and a set of edges, E.
 A tree is a collection of entities called nodes. Nodes are connected by
edges. Each node contains a value or data, and it may or may not have
a child node
 Tree is also a Graph.
6
We Should Know
 Visiting a Vertex: It means going on a particular vertex or checking a
vertex’s value.
 Exploration of Vertex: It means visiting all the adjacent vertices of a
selected node.
 Traversing: Traversing means passing through nodes in a specific
order
7
We Should Know
 Level-Order: It is a traversing method,
where we have to visit every node on a
level before going to a lower level.
* Breadth means the distance or measurement from side to
side of something; width; wideness; diameter; range; extent.
8
* Breadth First Search for a graph is similar to Breadth First
Traversal of a tree. The only catch here is, unlike trees, graphs
may contain cycles, so we may come to the same node again. To
avoid processing a node more than once, we use a Boolean
visited array. For simplicity, it is assumed that all vertices are
reachable from the starting vertex.
We Should Know
For example, in the following graph, we start traversal
from vertex 2. When we come to vertex 0, we look for
all adjacent vertices of it. 2 is also an adjacent vertex
of 0. If we don’t mark visited vertices, then 2 will be
processed again and it will become a non-terminating
process. A Breadth First Traversal of the following
graph is 2, 0, 3, 1.
9
10
Level-Order: 1 234 5678 9101112
1 234 5678 9101112BFS:
BFS & Level Order Example
11
Fig: 01 Fig: 02 Fig: 03
BFS Illustration
12
Fig: 04 Fig: 05 Fig: 06
13
Fig: 09Fig: 07 Fig: 08
14
Fig: 10
* BFS is just like Level Order
& it follow 3 simple rules
Rule 1 : Visit the adjacent unvisited vertex.
Mark it as visited. Insert it in a queue &
Display it.
Rule 2 : If no adjacent vertex is found,
remove the first vertex from the queue.
Rule 3 : Repeat Rule 1 and Rule 2 until the
queue is empty.
15
Breadth First Search Visualization
Step: 1
16
Step: 2
17
Step: 3
18
Step: 4
19
Step: 5
20
Step: 6
21
Step: 7
22
Step: 8
23
Step: 9
24
Step: 10
25
Step: 11
26
Step: 12
27
Step: 13
28
Step: 14
BFS (G, s) //Where G is the graph and s is the source node
let Q be queue.
Q.enqueue( s ) //Inserting s in queue until all its neighbour vertices are marked.
mark s as visited.
while ( Q is not empty)
//Removing that vertex from queue, whose neighbour will be visited now
v = Q.dequeue( )
//processing all the neighbours of v
for all neighbours w of v in Graph G
if w is not visited
Q.enqueue( w ) //Stores w in Q to further visit its neighbour
mark w as visited.
29
Pseudocode
30BFS Traversal Program (Java)
BFS Tree
31
Output
BFS(G) // starts from here
{
for each vertex u  V-{s}
{
color[u]=WHITE;
prev[u]=NIL;
d[u]=inf;
}
color[s]=GRAY;
d[s]=0; prev[s]=NIL;
Q=empty;
ENQUEUE(Q,s);
While(Q not empty)
{
u = DEQUEUE(Q);
for each v  adj[u]{
if (color[v] == WHITE){
color[v] = GREY;
d[v] = d[u] + 1;
prev[v] = u;
Enqueue(Q, v);
}
}
color[u] = BLACK;
}
}
Data: color[V], prev[V],d[V]
Breadth First Search Algorithm
32
r s t u








r s t u
v w x y
Vertex r s t u v w x y
color W W W W W W W W
d        
prev nil nil nil nil nil nil nil nil
Breadth-First Search: Example
33


0





r s t u
v w x y
sQ:
vertex r s t u v w x y
Color W G W W W W W W
d  0      
prev nil nil nil nil nil nil nil nil
Breadth-First Search: Example
34
1

0
1




r s t u
v x y
w rsQ:
w
vertex r s t u v w x y
Color G B W W W G W W
d 1 0    1  
prev s nil nil nil nil s nil nil
Breadth-First Search: Example
35
1

0
1
2
2


r s t u
v
w x
y
t xw rsQ:
vertex r s t u V w X y
Color G B G W W B G W
d 1 0 2   1 2 
prev s nil w nil nil s w nil
Breadth-First Search: Example
36
1
2
0
1
2
2


r s t u
v w x
y
vt xw rsQ:
vertex r s t u v w x y
Color B B G W G B G W
d 1 0 2  2 1 2 
prev s nil w nil r s w nil
Breadth-First Search: Example
37
1
2
0
1
2
2
3

v
w x
y
uvt xw rsQ:
vertex r s t u v w x y
Color B B B G G B G W
d 1 0 2 3 2 1 2 
prev s nil w t r s w nil
Breadth-First Search: Example
38
1
2
0
1
2
2
3
3
r s t u
v
w x y
yuvt xw rsQ:
vertex r s t u v w x y
Color B B B G G B B G
d 1 0 2 3 2 1 2 3
prev s nil w t r s w x
Breadth-First Search: Example
39
1
2
0
1
2
2
3
3
r s t u
v
w x y
yuvt xw rsQ:
vertex r s t u v w x y
Color B B B G G B B G
d 1 0 2 3 2 1 2 3
prev s nil w t r s w x
Breadth-First Search: Example
40
1
2
0
1
2
2
3
3
r s t u
v w x y
yuvt xw rsQ:
vertex r s t u v w x y
Color B B B B B B B G
d 1 0 2 3 2 1 2 3
prev s nil w t r s w x
Breadth-First Search: Example
41
1
2
0
1
2
2
3
3
r s t u
v w x y
yuvt xw rsQ:
vertex r s t u v w x y
Color B B B G B B B B
d 1 0 2 3 2 1 2 3
prev s nil w t r s w x
Breadth-First Search: Example
42
There are many applications Breadth First Search. Let’s discuss some of them.
1) Shortest Path and Minimum Spanning Tree for unweighted graph: In an
unweighted graph, the shortest path is the path with least number of edges.
With Breadth First, we always reach a vertex from given source using the
minimum number of edges. Also, in case of unweighted graphs, any spanning
tree is Minimum Spanning Tree and we can use Breadth first traversal for
finding a spanning tree.
2) Peer to Peer Networks: In Peer to Peer Networks like BitTorrent, Breadth
First Search is used to find all neighbor nodes.
3) Ford–Fulkerson method for computing the maximum flow in a flow network.
43
Applications of Breadth First Search
4) Crawlers in Search Engines: Crawlers build index using Breadth First Search.
The idea is to start from source page and follow all links from source and keep doing
same. Depth First Traversal can also be used for crawlers, but the advantage with
Breadth First Traversal is, depth or levels of the built tree can be limited.
5) Social Networking Websites: In social networks, we can find people within a
given distance ‘k’ from a person using Breadth First Search till ‘k’ levels.
6) GPS Navigation systems: Breadth First Search is used to find all neighboring
locations. Navigation systems such as the Google Maps, which can give directions to
reach from one place to another use BFS. They take your location to be the source
node and your destination as the destination node on the graph. (A city can be
represented as a graph by taking landmarks as nodes and the roads as the edges
that connect the nodes in the graph.) BFS is applied and the shortest route is
generated which is used to give directions or real time navigation.
44Applications of Breadth First Search
7) Broadcasting in Network: In networks, a broadcasted packet follows
Breadth First Search to reach all nodes.
8) In Garbage Collection: Breadth First Search is used in copying
garbage collection.
9) Cycle detection in undirected graph: In undirected graphs, either
Breadth First Search or Depth First Search can be used to detect cycle.
In directed graph, only depth first search can be used.
10) Path Finding: We can either use Breadth First or Depth First
Traversal to find if there is a path between two vertices.
45
Applications of Breadth First Search
The time complexity of BFS is, O(V + E)
where V is the number of nodes and E is the number of edges.
The space complexity can be expressed as, O(V),
where V is the cardinality of the set of vertices
46Time and Space Complexity
47
Conclusion
Breadth First Search (BFS) algorithm is a very important algorithm that traverses a
graph in a breadthward motion and uses a queue (FIFO, First-In-First-Out method)
to remember to get the next vertex to start a search, when a dead end occurs in any
iteration.
Breadth-first search produces a so-called breadth-first tree and it is same as level-
order traversing method.
Breadth-first search can be used to solve many problems in graph theory. It can
also
be applied to solve of many real life problems for example GPS Navigation systems,
Computer Networks, Facebook structure, Web Crawlers for search engine etc.
That is why As a computer engineer we should have a proper knowledge of Breadth
First Search (BFS).
Any
Questions ?
48
49
Thank You
Created and Presented by
Everyone

Contenu connexe

Tendances

Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithmMohd Arif
 
A presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmA presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmGaurav Kolekar
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languagesSOMNATHMORE2
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen ProblemSukrit Gupta
 
Artificial Intelligence Searching Techniques
Artificial Intelligence Searching TechniquesArtificial Intelligence Searching Techniques
Artificial Intelligence Searching TechniquesDr. C.V. Suresh Babu
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's AlgorithmTanmay Baranwal
 
Semantic nets in artificial intelligence
Semantic nets in artificial intelligenceSemantic nets in artificial intelligence
Semantic nets in artificial intelligenceharshita virwani
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 

Tendances (20)

Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
 
A presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmA presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithm
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
And or graph
And or graphAnd or graph
And or graph
 
Artificial Intelligence Searching Techniques
Artificial Intelligence Searching TechniquesArtificial Intelligence Searching Techniques
Artificial Intelligence Searching Techniques
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
 
Ontology engineering
Ontology engineering Ontology engineering
Ontology engineering
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Semantic nets in artificial intelligence
Semantic nets in artificial intelligenceSemantic nets in artificial intelligence
Semantic nets in artificial intelligence
 
Shortest Path in Graph
Shortest Path in GraphShortest Path in Graph
Shortest Path in Graph
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 

Similaire à Presentation on Breadth First Search (BFS)

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
 
artificial intelligence
artificial intelligence artificial intelligence
artificial intelligence ilias ahmed
 
Path Finding Solutions For Grid Based Graph
Path Finding Solutions For Grid Based GraphPath Finding Solutions For Grid Based Graph
Path Finding Solutions For Grid Based Graphacijjournal
 
Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsSigSegVSquad
 
Link Prediction in the Real World
Link Prediction in the Real WorldLink Prediction in the Real World
Link Prediction in the Real WorldBalaji Ganesan
 
PATH FINDING SOLUTIONS FOR GRID BASED GRAPH
PATH FINDING SOLUTIONS FOR GRID BASED GRAPHPATH FINDING SOLUTIONS FOR GRID BASED GRAPH
PATH FINDING SOLUTIONS FOR GRID BASED GRAPHacijjournal
 
Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7Traian Rebedea
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalAmrinder Arora
 
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptxPPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptxRaviKiranVarma4
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentationSubid Biswas
 
BFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal AlgorithmBFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal AlgorithmMSA Technosoft
 
Node Path Visualizer Using Shortest Path Algorithms
Node Path Visualizer Using Shortest Path AlgorithmsNode Path Visualizer Using Shortest Path Algorithms
Node Path Visualizer Using Shortest Path AlgorithmsIRJET Journal
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first searchHossain Md Shakhawat
 

Similaire à Presentation on Breadth First Search (BFS) (20)

Ai1.pdf
Ai1.pdfAi1.pdf
Ai1.pdf
 
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
 
Bfs dfs
Bfs dfsBfs dfs
Bfs dfs
 
artificial intelligence
artificial intelligence artificial intelligence
artificial intelligence
 
Path Finding Solutions For Grid Based Graph
Path Finding Solutions For Grid Based GraphPath Finding Solutions For Grid Based Graph
Path Finding Solutions For Grid Based Graph
 
Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding Algorithms
 
Breadth first search
Breadth first searchBreadth first search
Breadth first search
 
Link Prediction in the Real World
Link Prediction in the Real WorldLink Prediction in the Real World
Link Prediction in the Real World
 
PATH FINDING SOLUTIONS FOR GRID BASED GRAPH
PATH FINDING SOLUTIONS FOR GRID BASED GRAPHPATH FINDING SOLUTIONS FOR GRID BASED GRAPH
PATH FINDING SOLUTIONS FOR GRID BASED GRAPH
 
Data structure note
Data structure noteData structure note
Data structure note
 
Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7
 
Data structure
Data structureData structure
Data structure
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Adsa u2 ver 1.0.
Adsa u2 ver 1.0.Adsa u2 ver 1.0.
Adsa u2 ver 1.0.
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptxPPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
BFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal AlgorithmBFS, Breadth first search | Search Traversal Algorithm
BFS, Breadth first search | Search Traversal Algorithm
 
Node Path Visualizer Using Shortest Path Algorithms
Node Path Visualizer Using Shortest Path AlgorithmsNode Path Visualizer Using Shortest Path Algorithms
Node Path Visualizer Using Shortest Path Algorithms
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
 

Dernier

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf203318pmpc
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 

Dernier (20)

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 

Presentation on Breadth First Search (BFS)

  • 2. Dhaka International University 2 Presentation on Presented To Mr. Tahzib Ul Islam Assistant Professor Department of CSE Dhaka International University Presented By Group: Quiet Fools Name, Roll Shuvongkor Barman (38) Abdullah Al-Helal (33) Subarna (17) CSE-E59-7th
  • 3. 3 1. Introduction 2.What is BFS? 3. Necessary Terms 4. BFS Illustration with Example 5. Pseudocode of BFS 6. BFS Program (Java) and Output 7.Algorithm with Example 8. Application of BFS? 9.Time and Space Complexity 10. Conclusion 11. Questions
  • 4. BFS and its application in finding connected components of graphs were originally invented in 1945 by Konrad Zuse. He was a German Civil Engineer, inventor and computer pioneer. His greatest achievement was the world's first programmable computer. 4 Inventor of BFS Konrad Zuse
  • 5. 5 Breadth-first search (BFS) is an algorithm for traversing or searching Tree or Graph data structures. It starts at the tree root or some arbitrary node of a graph, sometimes referred to as a 'search key’ and explores all of the neighbor nodes at the present depth prior to moving on to the nodes at the next depth level. What is Breadth First Search (BFS)?
  • 6.  A Graph G=(V, E) consists a set of vertices, V, and a set of edges, E.  A tree is a collection of entities called nodes. Nodes are connected by edges. Each node contains a value or data, and it may or may not have a child node  Tree is also a Graph. 6 We Should Know
  • 7.  Visiting a Vertex: It means going on a particular vertex or checking a vertex’s value.  Exploration of Vertex: It means visiting all the adjacent vertices of a selected node.  Traversing: Traversing means passing through nodes in a specific order 7 We Should Know  Level-Order: It is a traversing method, where we have to visit every node on a level before going to a lower level.
  • 8. * Breadth means the distance or measurement from side to side of something; width; wideness; diameter; range; extent. 8 * Breadth First Search for a graph is similar to Breadth First Traversal of a tree. The only catch here is, unlike trees, graphs may contain cycles, so we may come to the same node again. To avoid processing a node more than once, we use a Boolean visited array. For simplicity, it is assumed that all vertices are reachable from the starting vertex. We Should Know
  • 9. For example, in the following graph, we start traversal from vertex 2. When we come to vertex 0, we look for all adjacent vertices of it. 2 is also an adjacent vertex of 0. If we don’t mark visited vertices, then 2 will be processed again and it will become a non-terminating process. A Breadth First Traversal of the following graph is 2, 0, 3, 1. 9
  • 10. 10 Level-Order: 1 234 5678 9101112 1 234 5678 9101112BFS: BFS & Level Order Example
  • 11. 11 Fig: 01 Fig: 02 Fig: 03 BFS Illustration
  • 12. 12 Fig: 04 Fig: 05 Fig: 06
  • 13. 13 Fig: 09Fig: 07 Fig: 08
  • 14. 14 Fig: 10 * BFS is just like Level Order & it follow 3 simple rules Rule 1 : Visit the adjacent unvisited vertex. Mark it as visited. Insert it in a queue & Display it. Rule 2 : If no adjacent vertex is found, remove the first vertex from the queue. Rule 3 : Repeat Rule 1 and Rule 2 until the queue is empty.
  • 15. 15 Breadth First Search Visualization Step: 1
  • 29. BFS (G, s) //Where G is the graph and s is the source node let Q be queue. Q.enqueue( s ) //Inserting s in queue until all its neighbour vertices are marked. mark s as visited. while ( Q is not empty) //Removing that vertex from queue, whose neighbour will be visited now v = Q.dequeue( ) //processing all the neighbours of v for all neighbours w of v in Graph G if w is not visited Q.enqueue( w ) //Stores w in Q to further visit its neighbour mark w as visited. 29 Pseudocode
  • 32. BFS(G) // starts from here { for each vertex u  V-{s} { color[u]=WHITE; prev[u]=NIL; d[u]=inf; } color[s]=GRAY; d[s]=0; prev[s]=NIL; Q=empty; ENQUEUE(Q,s); While(Q not empty) { u = DEQUEUE(Q); for each v  adj[u]{ if (color[v] == WHITE){ color[v] = GREY; d[v] = d[u] + 1; prev[v] = u; Enqueue(Q, v); } } color[u] = BLACK; } } Data: color[V], prev[V],d[V] Breadth First Search Algorithm 32
  • 33. r s t u         r s t u v w x y Vertex r s t u v w x y color W W W W W W W W d         prev nil nil nil nil nil nil nil nil Breadth-First Search: Example 33
  • 34.   0      r s t u v w x y sQ: vertex r s t u v w x y Color W G W W W W W W d  0       prev nil nil nil nil nil nil nil nil Breadth-First Search: Example 34
  • 35. 1  0 1     r s t u v x y w rsQ: w vertex r s t u v w x y Color G B W W W G W W d 1 0    1   prev s nil nil nil nil s nil nil Breadth-First Search: Example 35
  • 36. 1  0 1 2 2   r s t u v w x y t xw rsQ: vertex r s t u V w X y Color G B G W W B G W d 1 0 2   1 2  prev s nil w nil nil s w nil Breadth-First Search: Example 36
  • 37. 1 2 0 1 2 2   r s t u v w x y vt xw rsQ: vertex r s t u v w x y Color B B G W G B G W d 1 0 2  2 1 2  prev s nil w nil r s w nil Breadth-First Search: Example 37
  • 38. 1 2 0 1 2 2 3  v w x y uvt xw rsQ: vertex r s t u v w x y Color B B B G G B G W d 1 0 2 3 2 1 2  prev s nil w t r s w nil Breadth-First Search: Example 38
  • 39. 1 2 0 1 2 2 3 3 r s t u v w x y yuvt xw rsQ: vertex r s t u v w x y Color B B B G G B B G d 1 0 2 3 2 1 2 3 prev s nil w t r s w x Breadth-First Search: Example 39
  • 40. 1 2 0 1 2 2 3 3 r s t u v w x y yuvt xw rsQ: vertex r s t u v w x y Color B B B G G B B G d 1 0 2 3 2 1 2 3 prev s nil w t r s w x Breadth-First Search: Example 40
  • 41. 1 2 0 1 2 2 3 3 r s t u v w x y yuvt xw rsQ: vertex r s t u v w x y Color B B B B B B B G d 1 0 2 3 2 1 2 3 prev s nil w t r s w x Breadth-First Search: Example 41
  • 42. 1 2 0 1 2 2 3 3 r s t u v w x y yuvt xw rsQ: vertex r s t u v w x y Color B B B G B B B B d 1 0 2 3 2 1 2 3 prev s nil w t r s w x Breadth-First Search: Example 42
  • 43. There are many applications Breadth First Search. Let’s discuss some of them. 1) Shortest Path and Minimum Spanning Tree for unweighted graph: In an unweighted graph, the shortest path is the path with least number of edges. With Breadth First, we always reach a vertex from given source using the minimum number of edges. Also, in case of unweighted graphs, any spanning tree is Minimum Spanning Tree and we can use Breadth first traversal for finding a spanning tree. 2) Peer to Peer Networks: In Peer to Peer Networks like BitTorrent, Breadth First Search is used to find all neighbor nodes. 3) Ford–Fulkerson method for computing the maximum flow in a flow network. 43 Applications of Breadth First Search
  • 44. 4) Crawlers in Search Engines: Crawlers build index using Breadth First Search. The idea is to start from source page and follow all links from source and keep doing same. Depth First Traversal can also be used for crawlers, but the advantage with Breadth First Traversal is, depth or levels of the built tree can be limited. 5) Social Networking Websites: In social networks, we can find people within a given distance ‘k’ from a person using Breadth First Search till ‘k’ levels. 6) GPS Navigation systems: Breadth First Search is used to find all neighboring locations. Navigation systems such as the Google Maps, which can give directions to reach from one place to another use BFS. They take your location to be the source node and your destination as the destination node on the graph. (A city can be represented as a graph by taking landmarks as nodes and the roads as the edges that connect the nodes in the graph.) BFS is applied and the shortest route is generated which is used to give directions or real time navigation. 44Applications of Breadth First Search
  • 45. 7) Broadcasting in Network: In networks, a broadcasted packet follows Breadth First Search to reach all nodes. 8) In Garbage Collection: Breadth First Search is used in copying garbage collection. 9) Cycle detection in undirected graph: In undirected graphs, either Breadth First Search or Depth First Search can be used to detect cycle. In directed graph, only depth first search can be used. 10) Path Finding: We can either use Breadth First or Depth First Traversal to find if there is a path between two vertices. 45 Applications of Breadth First Search
  • 46. The time complexity of BFS is, O(V + E) where V is the number of nodes and E is the number of edges. The space complexity can be expressed as, O(V), where V is the cardinality of the set of vertices 46Time and Space Complexity
  • 47. 47 Conclusion Breadth First Search (BFS) algorithm is a very important algorithm that traverses a graph in a breadthward motion and uses a queue (FIFO, First-In-First-Out method) to remember to get the next vertex to start a search, when a dead end occurs in any iteration. Breadth-first search produces a so-called breadth-first tree and it is same as level- order traversing method. Breadth-first search can be used to solve many problems in graph theory. It can also be applied to solve of many real life problems for example GPS Navigation systems, Computer Networks, Facebook structure, Web Crawlers for search engine etc. That is why As a computer engineer we should have a proper knowledge of Breadth First Search (BFS).
  • 49. 49 Thank You Created and Presented by Everyone