Professional Documents
Culture Documents
3 DFS DLS Idfs
3 DFS DLS Idfs
SEARCH
ALGORITHMS - II
DEPTH FIRST SEARCH
DEPTH LIMITED SEARCH
ITERATIVE DEPTH FIRST SEARCH
Depth First Search
Depth-first search always expands DEPTH-FIRST the
deepest node in the current frontier of the search tree.
As those nodes are expanded, they are dropped from the
frontier, so then the search “backs up” to the next deepest
node that still has unexplored successors.
DFS Algorithm design
◦ DFS graph search
◦ DFS Tree search - Recursive design
Depth First Graph Search with LIFO Frontier
deepest
Depth First Tree Search – Recursive Design
DFS – Example (Search on binary tree for M –
goal node)
Example 2 – Depth First Search
Start
Goal
Arad
Arad
Search tree construction Arad
Zerind
Sibiu
Timisoara
Expanding Arad
Expanding Zerind
Arad
Sibiu Oradea
Zerind Timisoara
Arad
Zerind
Sibiu
Timisoara
Zerind
Sibiu Oradea
Timisoara
Expanding Oradea Expanding Sibiu
Sibiu
Oradea
Zerind
Sibiu
Timisoara
Oradea
Expanding
Sibiu
Rimnicu Vilcea
Pitesti Craiova
Solution Path
OPTIMALITY
◦ BOTH GRAPH SEARCH AND TREE SEARCH APPROACHES DOES NOT
RETURN OPTIMAL SOLUTION
Performance Measure for DFS Algorithms – Time, Space Complexity
TIME COMPLEXITY
◦ BOTH TREE SEARCH AND GRAPH SEARCH - O(BM) (B – BRANCHING FACTOR, M –
MAXIMUM DEPTH OF THE STATE SPACE)
SPACE COMPLEXITY
◦ GRAPH SEARCH – O(BM)
◦ TREE SEARCH – O(B*M) (NO EXPLORED SET - ONLY A SINGLE PATH FROM THE ROOT
TO A LEAF NODE, ALONG WITH THE REMAINING UNEXPANDED SIBLING NODES
FOR EACH NODE ON THE PATH. ONCE A NODE HAS BEEN EXPANDED, IT CAN BE
REMOVED FROM MEMORY AS SOON AS ALL ITS DESCENDANTS HAVE BEEN FULLY
EXPLORED.)
Pros and Cons – Depth First Search
Pros
◦ O(b*m) space complexity of Depth First Tree Search make is suitable for
many areas of AI
◦ Depth First Tree Search variant – Back tracking – requires only O(m)
space complexity and reduced time complexity using current state
modification
Cons
◦ Absence of optimality
◦ Incompleteness in infinite states paces – overcome by limiting the depth
of search - DLS
DEPTH LIMITED SEARCH
LIMIT L IS FIXED FOR THE DEPTH – TRAVERSAL IS DONE ONLY
UP TO THE DEPTH
TERMINATES WITH SUCCESS / FAILURE / CUT_OFF (LIMIT IS
REACHED AND THE GOAL STATE IS NOT FOUND)
IMPLEMENTATION
◦ MODIFICATION OF GRAPH SEARCH ALGORITHM OF DFS (ADDITION
OF LIMIT PARAMETER)
◦ ADDING LIMIT TO THE RECURSIVE TREE SEARCH ALGORITHM
DEPTH LIMITED TREE SEARCH
DLS - Example
Goal State
Returns cut_off
DEMONSTRATE THE SEARCH TREE CONSTRUCTIONS FOR
IDFS (TREE SEARCH) TO FIND THE PATH FROM ARAD TO
Example 2 PITESTI WITH LIMIT 2
L=2
Arad
Zerind Oradea
Sibiu
Timisoara
Arad
Fagaras
Arad Lugoj Arad Rimnicu Vilcea
Oradea
returns cut_off
Performance Measures
COMPLETENESS:
◦ Incomplete if limit L < d (depth of the shallowest goal node)
OPTIMALITY
◦ Non optimal if L > d
TIME COMPLEXITY
◦ O(bL)
SPACE COMPLEXITY
◦ Depth Limited Tree Search – Space Complexity O(b*) (b*-
effective branching factor)
Fixing the limit for DLS
For most problems, however, we will not know a good depth
limit until we have solved the problem (handled using
Iterative Deepening DFS)
For finite state spaces – diameter of the state space graph
gives a better depth limit
For the search in map of 20 cities – longest solution can
have 19 cities hence limit can be chosen as 19
ITERATIVE DEEPENING DEPTH
FIRST SEARCH / ITERATIVE
DEEPENING SEARCH
DLS with limit extended from 0 to d (till shallowest goal is reached)
EXAMPLE
Demonstrate the search tree constructions for
IDFS (Tree Search) to find the path from Arad to
Pitesti
Example 2
Arad
L=0
L=1
Arad
Zerind
Sibiu
Timisoara
L=2
Arad
Timisoara Sibiu
Zerind Oradea
Arad
Arad Fagaras
Arad Rimnicu Vilcea
Oradea Lugoj
L=3
Arad
Timisoara Sibiu
Zerind
Zerind
Timisoara Arad
Arad Rimnicu Vilcea
Sibiu Oradea Lugoj
Craiova
Zerind
Sibiu Pitesti
Zerind Mehadia Timisoara Sibiu
Timisoara Sibiu
PATH COST = 317 L=3 Solution by Iterative Depth First Tree Search
PERFORMANCE
COMPLETENESS – Complete when b is finite (like BFS)
OPTIMALITY – Optimal when path cost is non decreasing function of
the depth of the node
TIME COMPLEXITY
◦ Node at the top level of the search are visited multiple times (initial node and
the nodes closer to the initial nodes)
SPACE COMPLEXITY
◦ Iterative Depth First Tree Search O(b*d)
Bidirectional Search
Bidirectional search is implemented by
replacing the goal test with a check to see
whether the frontiers of the two searches
intersect; if they do, a solution has been
found.
Time and space complexity O(bd/2)
Drawback:
Computing predecessors for a goal
for problems with multiple goal states and for
problems such as “No queens attacks another
queen”