Understanding Graph Traversal
Algorithms: A Deep Dive into BFS
and DFS
Graph
Traversal
Algorithm
Graph Traversal
Algorithm
Traversing the graph means examining all
the nodes and vertices of the graph. There
are two standard methods by using which,
we can traverse the graphs.
• Breadth First Search (BFS) - BFS
traversing the graph from root node
and explores all the nearest nodes and
by process explore all the unexplored
nodes until it finds the goal.
• Depth First Search (DFS) - DFS
algorithm starts with the initial node of
the graph, and then goes to deeper
and deeper until we find the goal node
or the node which has no children.
DIFFERENCE BETWEEN BFS
AND DFS
Breadth First Search (BFS) Depth First Search (DFS)
BFS use queue data structure
to store un-explored nodes.
Uses stack data structure to
store un-explored nodes.
BFS is slower and require
more memory.
DFS is faster and require less
memory.
Shortest path, GPS navigation
systems are real-time
applications of BFS
Topological sorting, path
finding are real-time
applications of DFS
Graph Solving
We will apply BFS and DFS on this graph
BFS
1
2 4
4 5
5 3
3
ф
Q:
Q:
Q:
Q:
Q:
Q: Visited:
Visited:
Visited:
Visited:
Visited:
Visited:
ф
1
1,2
1,2,4
1,2,4,5
1,2,4,5,3
Here 1,2,4,5,3 are the Traversal order for the graph
DFS
S Visited:
Visited:
Visited:
Visited:
Visited:
Visited:
ф
1
1,4
1,4,3
1,4,3,2
1,4,3,2,5
1
4
2
3
2
ф
2
5
S
S
S
S
S
Here 1,4,3,2,5 are the Traversal order for the graph
Thanks

Understanding Graph Traversal Algorithms A Deep Dive into BFS and DFS

  • 1.
    Understanding Graph Traversal Algorithms:A Deep Dive into BFS and DFS Graph Traversal Algorithm
  • 2.
    Graph Traversal Algorithm Traversing thegraph means examining all the nodes and vertices of the graph. There are two standard methods by using which, we can traverse the graphs. • Breadth First Search (BFS) - BFS traversing the graph from root node and explores all the nearest nodes and by process explore all the unexplored nodes until it finds the goal. • Depth First Search (DFS) - DFS algorithm starts with the initial node of the graph, and then goes to deeper and deeper until we find the goal node or the node which has no children.
  • 3.
    DIFFERENCE BETWEEN BFS ANDDFS Breadth First Search (BFS) Depth First Search (DFS) BFS use queue data structure to store un-explored nodes. Uses stack data structure to store un-explored nodes. BFS is slower and require more memory. DFS is faster and require less memory. Shortest path, GPS navigation systems are real-time applications of BFS Topological sorting, path finding are real-time applications of DFS
  • 4.
    Graph Solving We willapply BFS and DFS on this graph
  • 5.
    BFS 1 2 4 4 5 53 3 ф Q: Q: Q: Q: Q: Q: Visited: Visited: Visited: Visited: Visited: Visited: ф 1 1,2 1,2,4 1,2,4,5 1,2,4,5,3 Here 1,2,4,5,3 are the Traversal order for the graph
  • 6.
  • 7.