Search Techniques


Depth First Search

Q. Describe Depth First Search algorithm along with its merits and demerits. How is it different from Depth-First Iterative Deepening Search.

Ans. Depth-first searches are performed by diving downward into a tree as quickly possible. It does this by always generating a child node from the most recently expanded node, then generating that child's children, and so on until a goal found or some cutoff depth point d is reached. If a goal is not found when a 1 node is reached or at the cutoff point, the program backtracks to the most recently expanded node and generates another of its children. This process continues until goal is found or failure occurs.

The following figure shows an example of a depth-first search:

Depth-first places the newly generated children at the head of the queue so that they will be chosen first The search proceeds as follows.

1. Place the starting node s on the queue.
2. If the queue is empty, return failure and stop.
3. If the first element on the queue is a goal node g, return success and stop. Otherwise,
4. Remove and expand the first element, and place the children at the front of the queue (in any order).
5. Return to step 2.

The depth-first search is preferred over the breadth-first when the search tree is known to have a plentiful number of goals. Otherwise, depth-first may never find a solution. The depth cutoff also introduces some problems. If it is set too shallow, goals may be missed; if set too deep, extra computation may be performed.

The time complexity of the depth-first tree search is the same as that for breadth-first, O(bd). It is less demanding in space requirements, however, since only the path from the starting node to the current node needs to be stored. Therefore, if the depth cutoff is d, the space complexity is .just O(d).

Depth-First Iterative Deepening Search (June 02)

Depth-first iterative deepening searches are performed as a form of repetitive depth first search moving to a successively deeper depth with each iteration. It begins by performing a depth-first search to a depth of one.

It then discards all nodes generated and starts over doing a search to a depth of two. If no goal has been found, it discards all nodes generated and does a depth-first search to a depth of three. This process continues until a goal node is found or some maximum depth is reached.

Since the depth-first iterative deepening search expands all nodes at a given depth before expanding nodes at a greater depth, it is guaranteed to find a shortest- path solution. The main disadvantage of this method is that it performs wasted computations before reaching a goal depth. Even so, it has been shown to be asymptotically optimal over depth and breadth first search in terms of time and space complexity. That is, depth- and breadth-first searches take at least as much time and memory as depth-first iterative deepening searches for increasingly large searches. The time and space complexities of this search are O(bd) and O(d) respectively.

This search algorithm works basically the same as the depth-first search algorithm for a single iteration. However, it terminates the search at depth d on each iteration if no goal has been found, removes all nodes from the queue, increments d by one, and initiates the search again.


Q. Compare Depth-First Search and Breadth-First Search methods. (June 01, June 03)

Ans. Please refer to the previous questions for details. The depth-first search is preferred over the breadth-first when the search tree is known to have a plentiful number of goals. Otherwise, depth-first may never find a solution.

 
          AI Contents  
©Universal Teacher Publications Web: www.universalteacherpublications.com.