Computer Science Related Others Courses AvailableThe Best Codder.blogspot.com
Posts

Depth-first Search in AI

2 min read

 Depth-first Search

  • Depth-first search isa recursive algorithm for traversing a tree or graph data structure.
  • It is called the depth-first search because it starts from the root node and follows each path to its greatest depth node before moving to the next path.
  • DFS uses a stack data structure for its implementation.
  • The process of the DFS algorithm is similar to the BFS algorithm.

Note: Backtracking is an algorithm technique for finding all possible solutions using recursion.

Advantage:

  • DFS 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 (if it traverses in the right path).

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 sometime it may go to the infinite loop.

Example:

In the below search tree, we have shown the flow of depth-first search, and it will follow the order as:

Root node--->Left node ----> right node.

It will start searching from root node S, and traverse A, then B, then D and E, after traversing E, it will backtrack the tree as E has no other successor and still goal node is not found. After backtracking it will traverse node C and then G, and here it will terminate as it found goal node.

Uninformed Search Algorithms

Completeness: DFS search algorithm is complete within finite state space as it will expand every node within a limited search tree.

Time Complexity: Time complexity of DFS will be equivalent to the node traversed by the algorithm. It is given by:

T(n)= 1+ n2+ n3 +.........+ nm=O(nm)

Where, m= maximum depth of any node and this can be much larger than d (Shallowest solution depth)

Space Complexity: DFS algorithm needs to store only single path from the root node, hence space complexity of DFS is equivalent to the size of the fringe set, which is O(bm).

Optimal: DFS search algorithm is non-optimal, as it may generate a large number of steps or high cost to reach to the goal node.

You may like these posts

  •  1. Depth-Limited Search Algorithm:A depth-limited search algorithm is similar to depth-first search with a predetermined limit. Depth-limited search can solve the drawback of…
  •  Breadth-first SearchBreadth-first search is the most common search strategy for traversing a tree or graph. This algorithm searches breadthwise in a tree or graph, so it is c…
  •  Depth-first SearchDepth-first search isa recursive algorithm for traversing a tree or graph data structure.It is called the depth-first search because it starts from the root…
  •   A* Search Algorithm:A* search is the most commonly known form of best-first search. It uses heuristic function h(n), and cost to reach the node n from the start state g…
  •  Knowledge-Based System in Artificial intelligenceAn intelligent agent needs knowledge about the real world for taking decisions and reasoning to act effic…
  •  Best First Search Algorithm(Greedy search)Best-first Search Algorithm (Greedy Search):Greedy best-first search algorithm always selects the path which appears best at that mo…

Post a Comment

© 2025AI & MI. The Best Codder All rights reserved. Distributed by