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

More Related Content

What's hot

Topological Sorting
Topological SortingTopological Sorting
Topological SortingShahDhruv21
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsMohamed Loey
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsMohamed Loey
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptSeethaDinesh
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTUREArchie Jamwal
 
I.BEST FIRST SEARCH IN AI
I.BEST FIRST SEARCH IN AII.BEST FIRST SEARCH IN AI
I.BEST FIRST SEARCH IN AIvikas dhakane
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentationAlizay Khan
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data StructureAnuj Modi
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Problem solving agents
Problem solving agentsProblem solving agents
Problem solving agentsMegha Sharma
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentationSubid Biswas
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IMohamed Loey
 
Depth first search and breadth first searching
Depth first search and breadth first searchingDepth first search and breadth first searching
Depth first search and breadth first searchingKawsar Hamid Sumon
 

What's hot (20)

Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
I.BEST FIRST SEARCH IN AI
I.BEST FIRST SEARCH IN AII.BEST FIRST SEARCH IN AI
I.BEST FIRST SEARCH IN AI
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
Iterative deepening search
Iterative deepening searchIterative deepening search
Iterative deepening search
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Problem solving agents
Problem solving agentsProblem solving agents
Problem solving agents
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
 
Depth first search and breadth first searching
Depth first search and breadth first searchingDepth first search and breadth first searching
Depth first search and breadth first searching
 

Similar to 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
 
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
 

Similar to 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
 
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
 
Graph theory
Graph theory Graph theory
Graph theory
 

Recently uploaded

Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsDILIPKUMARMONDAL6
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 

Recently uploaded (20)

Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teams
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 

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