Unit-3 DFS
Unit-3 DFS
2
Example of DFS
3
Advantages
•It requires very less memory as it only needs to store a stack of
the nodes on the path from root node to the current node.
•It takes less time to reach to the goal node than BFS algorithm.
Disadvantage
•There is the possibility that many states keep re-occurring and
there is no guarantee of finding the solution.
•DFS Algorithm goes for deep down searching and sometimes it
may go to the infinite loop.
4
Time complexity: Equivalent to the
number of nodes traversed in DFS. T(n) = 1
+ n^2 + n^3 + ... + n^d = O(n^d)
d = the depth of the search tree = the
number of levels of the search tree.
n^i = number of nodes in level i
Space complexity:DFS has a space
complexity of O(V) due to the recursion
stack
5
• Completeness: DFS is complete if the search
tree is finite, meaning for a given finite search
tree, DFS will come up with a solution if it
exists.
Optimality: DFS is not optimal, meaning the
number of steps in reaching the solution, or
the cost spent in reaching it is high.
6
7
8
9
10