Professional Documents
Culture Documents
2.3-Uninformed Search Algorithms-060224
2.3-Uninformed Search Algorithms-060224
Artificial Intelligence
(BITE308L)
Uninformed Search
Algorithms
Dr. S. Hemalatha
School of Computer Science Engineering & Information Systems
VIT, Vellore
• Breadth-first Search
• Depth-first Search
• Uniform cost search
• Depth-limited Search
• Iterative deepening depth-first search
• Bidirectional Search
Prepared by S.Hemalatha/SCORE
1
06-02-2024
Prepared by S.Hemalatha/SCORE
Bfs - algorithm
Prepared by S.Hemalatha/SCORE
2
06-02-2024
BFS – example
Prepared by S.Hemalatha/SCORE
Prepared by S.Hemalatha/SCORE
3
06-02-2024
Prepared by S.Hemalatha/SCORE
• Space Complexity:
– Space complexity of BFS algorithm is given by the Memory size of frontier which is
𝑶 𝒃𝒅
• Completeness:
– BFS is complete, which means if the shallowest goal node is at some finite depth, then
BFS will find a solution.
• Optimality:
– BFS is optimal if path cost is a non-decreasing function of the depth of the node
Prepared by S.Hemalatha/SCORE
4
06-02-2024
• Disadvantages:
– It requires lots of memory since each level of the tree must be saved into memory to
expand the next level.
– BFS needs lots of time if the solution is far away from the root node.
Prepared by S.Hemalatha/SCORE
Note:
• Backtracking is an algorithm technique for finding all possible solutions using
recursion
Prepared by S.Hemalatha/SCORE
5
06-02-2024
dfs - algorithm
Prepared by S.Hemalatha/SCORE
DFS – example
Prepared by S.Hemalatha/SCORE
6
06-02-2024
Prepared by S.Hemalatha/SCORE
Prepared by S.Hemalatha/SCORE
7
06-02-2024
• Optimality:
– Considered to be non-optimal
• As it may generate a large number of steps or high cost to reach to the goal node
Prepared by S.Hemalatha/SCORE
• Advantages:
– 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
• Disadvantages:
– 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
Prepared by S.Hemalatha/SCORE
8
06-02-2024
Prepared by S.Hemalatha/SCORE
Prepared by S.Hemalatha/SCORE
9
06-02-2024
Prepared by S.Hemalatha/SCORE
Depth-limited search
Example
Prepared by S.Hemalatha/SCORE
10
06-02-2024
Prepared by S.Hemalatha/SCORE
Prepared by S.Hemalatha/SCORE
11
06-02-2024
• Uniform-cost search expands nodes according to their path costs form the root node
– Used to solve any graph/tree where the optimal cost is in demand
• A uniform-cost search algorithm is implemented by the priority queue
– Gives maximum priority to the lowest cumulative cost
• Uniform cost search is equivalent to BFS algorithm
– If the path cost of all edges is the same
Prepared by S.Hemalatha/SCORE
Prepared by S.Hemalatha/SCORE
12
06-02-2024
Uniform-cost Search
Example
Prepared by S.Hemalatha/SCORE
Uniform-cost Search
Example (another)
Prepared by S.Hemalatha/SCORE
13
06-02-2024
Uniform-cost Search
Time Complexity
• Completeness:
– Said to be complete, as if there is a solution, UCS will find it
• Time Complexity:
– Cost of optimal solution: 𝑪∗
– Each step to get closer to the goal node: 𝜺
– Then the number of steps: 𝑪∗⁄𝜺 + 𝟏
• +1 is taken here, as we start from state 0 and end to 𝑪∗ ⁄𝜺
– Hence, the worst-case time complexity of UCS:
𝑪∗ ⁄𝜺
𝑶 𝒃𝟏
Prepared by S.Hemalatha/SCORE
Uniform-cost Search
Time Complexity
• Space Complexity:
𝑪∗ ⁄𝜺
𝑶 𝒃𝟏
– Same logic as that of time complexity is applicable
• Optimal:
– UCS is always optimal as it only selects a path with the lowest path cost
Prepared by S.Hemalatha/SCORE
14
06-02-2024
Prepared by S.Hemalatha/SCORE
Iddf-Search
algorithm
Prepared by S.Hemalatha/SCORE
15
06-02-2024
Iddf-Search
example (book)
Prepared by S.Hemalatha/SCORE
Iddf-Search
Example
Prepared by S.Hemalatha/SCORE
16
06-02-2024
Iddf-Search
Time Complexity
• Completeness:
– This algorithm is complete is if the branching factor is finite
• Time Complexity:
– 𝑏: Branching factor
– 𝑑: Depth
– Worst-case time complexity: 𝑶 𝒃𝒅
• Space Complexity: 𝑶 𝒃𝒅
• Optimal:
– If path cost is a non- decreasing function of the depth of the node
Prepared by S.Hemalatha/SCORE
Prepared by S.Hemalatha/SCORE
17
06-02-2024
Bidirectional Search
Example
• Forward direction:
– It starts traversing from
node 1 in the
• Backward direction:
– Starts from goal node 16
• Terminates at:
– Node 9 where two searches
meet
Prepared by S.Hemalatha/SCORE
Bidirectional Search
/ /
Motivation behind this search: 𝑏 +𝑏 is much less than 𝑏
• Goal test replaced with a check to see if the frontiers of the two searches
intersect
– if they do, a solution has been found
the first such solution found may not be optimal
even if the two searches are both breadth-first;
some additional search is required to make sure there isn’t another short-
cut across the gap
• The check can be done
– when each node is generated / selected for expansion
– & will take constant time
Prepared by S.Hemalatha/SCORE
18
06-02-2024
Bidirectional Search
/ /
Motivation behind this search: 𝑏 +𝑏 is much less than 𝑏
• Example:
– If a problem has solution depth d=6, and each direction runs breadth-first search
one node at a time, then in the worst case the two searches meet when they have
generated all of the nodes at depth 3
– For b=10, this means a total of 2,220 node generations, compared with 1,111,110
for a standard breadth-first search
/
• Time complexity: O 𝑏
• Space complexity: O 𝑏 /
– Can be reduced this by roughly half if one of the two searches is done by iterative
deepening,
• but at least one of the frontiers must be kept in memory so that the intersection check
can be done
• This space requirement is the most significant weakness of bidirectional search
Prepared by S.Hemalatha/SCORE
Bidirectional Search
Advantages & Disadvantages
• Advantages:
– Bidirectional search is fast
– Bidirectional search requires less memory
• Disadvantages:
– Implementation of the bidirectional search tree is difficult
– In bidirectional search, one should know the goal state in advance
Prepared by S.Hemalatha/SCORE
19
06-02-2024
Bidirectional Search
Time Complexity
• Completeness:
– Bidirectional Search is complete if we use BFS in both searches
• Time Complexity:
– Time complexity of bidirectional search using BFS is O(bd)
• Space Complexity:
– Space complexity of bidirectional search is O(bd)
• Optimal:
– Bidirectional search is Optimal
Prepared by S.Hemalatha/SCORE
Comparison
uninformed search algorithms
Prepared by S.Hemalatha/SCORE
20