Graph Traversal
Breadth First Search & Depth First Search
In Data Structures
Presentation By
Shreedharshini V
Shrisena M
Sriharan K
Srimathi K
Table of Contents
01 02 03
04 05
Introduction Breadth First Search Depth First Search
Difference Between
BFS & DFS
Application of
BFS & DFS
Introduction
Graph
A Set of vertices and edges is known as graph
Directed & Undirected
Weighted & Unweighted
Cyclic & Acyclic
Breadth First Search Algorithm
Breadth First Search algorithm visits
efficiently and marks all node, the critical nodes
in a graph in a breadthwise
manner.
Breadth First Search starts traversing
from the root node and then select all unvisited
adjacent nodes of the selected node
Queue data structures is used in the BFS
algorithm.
1
2
3
4 5 6
7 8
2
Example of BFS Algorithm
0
A
B C
D E F G
1 2
3 4 5 6
0 1 2 3 4 5 6
A B C D E F G
BFS Nodes: A B C D E
BFS Vertices: 0 1 2 3 4
Depth First Search Algorithm
Depth First Search algorithm for finding or
traversing graphs or trees in depth wise
direction.
The execution of this algorithm begins
with the root node and explores each branch
before backtracking .
DFS uses stack data structure to
remember,to get subsequent vertex and start a
search whenever a dead end appears in any
iteration.
1
2 3
4 5 6
7 8
Example of DFS Algorithm
0
4
DFS Nodes: A B C D
DFS Vertices: 0 1 2 3
Difference between BFS and DFS
Breadth First Search finds shortest
path to the destination
DFS goes to the bottom of a
subtree, then backtracks
Difference between BFS and DFS
BFS uses a queue to keep track of
the following location to visit
BFS uses a stack to keep track of the
following location to visit
Difference between BFS and DFS
BFS uses (FIFO) First In First Out
order for implementation
DFS uses (LIFO) Last In First Out
order for implementation
Difference between BFS and DFS
BFS requires more memory as
compared to DFS
DFS requires Less memory as
compared to BFS
Difference between BFS and DFS
BFS algorithm gives the Shallowest
path solution
DFS algorithm gives does not guarantee
Shallowest path solution
Difference between BFS and DFS
In the BFS algorithm, if you do not
find any goal, you may need to
expand many nodes before the
solution is found
In the BFS algorithm, if you do not
find any goal, the backtracking will
Start from leaf node.
Application of BFS
BFS algorithm can easily create the
shortest path and a minimum
spanning tree to visit all the graphs
vertices in the shortest time
,possibly in high accuracy
Un- Weighted Graph:
Application of BFS
BFS algorithm implemented to
locate all the neighboring nodes in
peer-to-peer network and this will
find the required data faster.
P2P Networks:
Application of BFS
Search Engine or Web crawlers can
Quickly build multiple levels of
indexes by employing BFS and starts
implementing from the source and
then its all links from the source
Web Crawlers
Application of DFS
It is primarily used for scheduling
jobs for the given dependencies
among the group of jobs. In
computer science ,It is used for
instruction Scheduling, data
serialization and compliation task
order
Deleting a Cycle
Application of DFS
DFS algorithm can be easily adapted
to search all solutions to a maze by
including nodes on the existing path
in the visited set
Solving Puzzles
Thank
You…

bfs and dfs (data structures).pptx

  • 1.
    Graph Traversal Breadth FirstSearch & Depth First Search In Data Structures Presentation By Shreedharshini V Shrisena M Sriharan K Srimathi K
  • 2.
    Table of Contents 0102 03 04 05 Introduction Breadth First Search Depth First Search Difference Between BFS & DFS Application of BFS & DFS
  • 3.
    Introduction Graph A Set ofvertices and edges is known as graph Directed & Undirected Weighted & Unweighted Cyclic & Acyclic
  • 4.
    Breadth First SearchAlgorithm Breadth First Search algorithm visits efficiently and marks all node, the critical nodes in a graph in a breadthwise manner. Breadth First Search starts traversing from the root node and then select all unvisited adjacent nodes of the selected node Queue data structures is used in the BFS algorithm. 1 2 3 4 5 6 7 8 2
  • 5.
    Example of BFSAlgorithm 0 A B C D E F G 1 2 3 4 5 6 0 1 2 3 4 5 6 A B C D E F G BFS Nodes: A B C D E BFS Vertices: 0 1 2 3 4
  • 7.
    Depth First SearchAlgorithm Depth First Search algorithm for finding or traversing graphs or trees in depth wise direction. The execution of this algorithm begins with the root node and explores each branch before backtracking . DFS uses stack data structure to remember,to get subsequent vertex and start a search whenever a dead end appears in any iteration. 1 2 3 4 5 6 7 8
  • 8.
    Example of DFSAlgorithm 0 4 DFS Nodes: A B C D DFS Vertices: 0 1 2 3
  • 10.
    Difference between BFSand DFS Breadth First Search finds shortest path to the destination DFS goes to the bottom of a subtree, then backtracks
  • 11.
    Difference between BFSand DFS BFS uses a queue to keep track of the following location to visit BFS uses a stack to keep track of the following location to visit
  • 12.
    Difference between BFSand DFS BFS uses (FIFO) First In First Out order for implementation DFS uses (LIFO) Last In First Out order for implementation
  • 13.
    Difference between BFSand DFS BFS requires more memory as compared to DFS DFS requires Less memory as compared to BFS
  • 14.
    Difference between BFSand DFS BFS algorithm gives the Shallowest path solution DFS algorithm gives does not guarantee Shallowest path solution
  • 15.
    Difference between BFSand DFS In the BFS algorithm, if you do not find any goal, you may need to expand many nodes before the solution is found In the BFS algorithm, if you do not find any goal, the backtracking will Start from leaf node.
  • 16.
    Application of BFS BFSalgorithm can easily create the shortest path and a minimum spanning tree to visit all the graphs vertices in the shortest time ,possibly in high accuracy Un- Weighted Graph:
  • 17.
    Application of BFS BFSalgorithm implemented to locate all the neighboring nodes in peer-to-peer network and this will find the required data faster. P2P Networks:
  • 18.
    Application of BFS SearchEngine or Web crawlers can Quickly build multiple levels of indexes by employing BFS and starts implementing from the source and then its all links from the source Web Crawlers
  • 19.
    Application of DFS Itis primarily used for scheduling jobs for the given dependencies among the group of jobs. In computer science ,It is used for instruction Scheduling, data serialization and compliation task order Deleting a Cycle
  • 20.
    Application of DFS DFSalgorithm can be easily adapted to search all solutions to a maze by including nodes on the existing path in the visited set Solving Puzzles
  • 21.