Tuesday, August 3, 2021

Introduction to DFS (Depth First Search)

Intro:

The Depth First Search known as DFS is an algorithm for traversing a graph or tree data structure. DFS traversing start from a root node. DFS tries to visit in-depth in all possible ways after that comes back to the root node, then goes to another depth, and so on.
Let's try to visualize the scenario.
Here, the red line shows us starting the traversing and the blue line shows after traversing it comes back to the root node, this is simply called backtracking.

The one possible traversing can be,
1-2-3-4-5-6-7-8-9-10
Also,
1-2-3-4-5-8-6-7-9-10 can be possible.

The Complexity of DFS traversing is O(v+E), V is the number of nodes, and E is the number of edges. This is really easy to understand.

I the near future we will discuss some DFS related problems, then it will be more clear.


No comments:

Post a Comment