You are on page 1of 10

Problem Solving Agents

DEPTH FIRST DEPTH LIMITED ITERATIVE


SEARCH (DFS) SEARCH DEEPENING SEARCH
Depth First Search (DFS)
Depth-first search (DFS) is an algorithm for traversing
or searching a tree, tree structure, or graph. One
starts at the root (selecting some node as the root in
the graph case) and explores as far as possible along
each branch before backtracking.
Algorithm:
1. Push the root node onto a stack.
2. Pop a node from the stack and examine it.
3. If the element sought is found in this node, quit the
search and return a result.
4. Otherwise push all its successors (child nodes) that
have not yet been discovered onto the stack.
5. If the stack is empty, every node in the tree has been
examined – quit the search and return "not found".
6. If the stack is not empty, repeat from Step 2.
DFS Algorithm
Depth Limited Search
The unbounded tree problem appeared in DFS can be fixed
by imposing a limit on the depth that DFS can reach, this
limit we will call depth limit l, this solves the infinite path
problem.
Depth limited search (DLS) is a modification of depth-first
search that minimizes the depth that the search algorithm
may go.
In addition to starting with a root and goal node, a depth is
provided that the algorithm will not descend below.
Any nodes below that depth are omitted from the search.
This modification keeps the algorithm from indefinitely
cycling by halting the search after the pre-imposed depth.
Depth-limited search can terminate with two conditions:
1. If the solution is found.
2. If there is no solution within given depth limit.
Process: If depth is fixed to 2, DLS carries out depth first
search till second level in the search tree.
Algorithm:
1. Determine the start node and the search depth.
2. Check if the current node is the goal node.
If not: Do nothing
If yes: return
3. Check if the current node is within the specified search
depth
If not: Do nothing
If yes: Expand the node and save all of its successors
in a stack.
4. Call DLS recursively for all nodes of the stack and go back
to step 2.
Iterative Deepening Search
Iterative Deepening Search (IDS) is a derivative of DLS and
combines the feature of depth-first search with that of
breadth-first search.
IDS operate by performing DLS searches with increased
depths until the goal is found.
The depth begins at one, and increases until the goal is
found, or no further nodes can be enumerated.
By minimizing the depth of the search, we force the
algorithm to also search the breadth of a graph.
If the goal is not found, the depth that the algorithm is
permitted to search is increased and the algorithm is
started again.
Iterative Deepening Search (IDS)

You might also like