CSC 325 AI Lecture03 Uninformed Search Fall2024 22092024 113727am
CSC 325 AI Lecture03 Uninformed Search Fall2024 22092024 113727am
Artificial Intelligence
Lecture - 3:
Uninformed Search
7 Bidirectional Search
8
Search Strategies
Section - 1
Search Strategies
▪ Definition
• A search strategy is defined by picking the order of node expansion
▪ Strategies are evaluated along the following dimensions:
• completeness: does it always find a solution if one exists?
• optimality: does it always find a least-cost solution?
• time complexity: number of nodes generated
• space complexity: maximum number of nodes in memory
▪ Time and space complexity are measured in terms of
• b: maximum branching factor of the search tree
• d: depth of the least-cost solution
• m: maximum depth of the state space (may be ∞)
© Dr. Tariq 2024 Department of Computer Sciences | Bahria University 4
Types of Search Strategies
▪ Uninformed Search Algorithms
• No domain-specific knowledge beyond the problem definition.
• Systematically explores the search space.
• Does not consider proximity(nearness/closeness) to the goal.
• Relies only on the problem formulation (initial state, goal state, actions,
transition model).
• Common methods:
o Breadth-First Search (BFS)
o Depth-First Search (DFS)
o Uniform-Cost Search (UCS)
▪ They are implemented using FIFO data structures, the algorithm will maintain a
list of the currently active paths and in each round of the algorithm repeat
following three steps until solution is not found or no further expansion is
possible.
1. Remove the first path from the list of paths.
2. Generate a new path for every possible follow-up nodes.
3. Append the list of newly generated paths to the end of the list of paths (to
ensure paths are really being visited in breadth-first order).
Completeness
Yes, if b is finite
Optimally
Yes (assuming cost = 1 per step) otherwise No.
Time Complexity
1+b+b2+…+bd = O(bd) i.e., exponential in d
Space Complexity
O(bd)
b – maximum branching factor of the search tree
d – is the depth of the shallowest solution
© Dr. Tariq 2024 Department of Computer Sciences | Bahria University 18
Exponential Growth
Depth Nodes Time Memory
2 110 0.11 millisecond 107 kbytes
4 11,110 11 Millisecond 10.6 megabytes
6 106 1.1 seconds 1 gigabyte
8 108 2 Minutes 103 gigabytes
10 1010 3 Hours 10 terabytes
12 1012 13 Days 1 petabyte
14 1014 3.5 years 99 petabytes
16 1016 350 years 10 exabytes
Time and memory requirements for breadth-first search, assuming a branching factor
of 10, 100 bytes per node and searching 1000 nodes/second
▪ Explanation – Nodes found but yet to be reviewed are stored in a LIFO queue
(stack).
• Exhaustive means DFS can search every node in the graph to find the goal. If the goal is
not present in the graph, the algorithm will terminate, but will search each and every node
in a systematic way.
• Therefore, the DFS need to store only single path from node to leaf along with
unexpanded sibling at each level of depth.
• Each node explored is put on the front of frontier.
Optimally
No
Time Complexity
O(bm)
Space Complexity
O(bm)
b – maximum branching factor of the search tree
m – maximum depth of the state space (may be infinite)
© Dr. Tariq 2024 Department of Computer Sciences | Bahria University 30
Uniform Cost Search
Section - 4
Uniform-Cost Search (UCS)
▪ Definition
• Unlike BFS, instead of expanding shallowest node, uniform-cost
Search (UCS) expands the node with lowest path cost.
▪ Explanation
• UCS finds the least-cost path through a graph by maintaining an
ordered list of nodes in order of least-greatest cost (Priority Queue).
This allows us to evaluate the least cost path first.
• Let g(n) = cost of path from start node s to current node n
• Sort nodes by increasing value of g
H
path: (G,F) → (F,C) → (C,S) → (S,nil)
: S→C→F→G
Cost: S-C = 4, C-F = 2, F-G = 1
: S-G = 7
Optimally
• Yes
44
Depth-Limited Search (DLS)
❖The depth limit is often based on the domain knowledge of the
problem.
❖Example
In the map of Romania, we can see that there are 20 cities, therefore
possibly l = 19 since if solution exists that would reach at the depth of
19. Or if we look at the map carefully every city from any city can be
reach in 9 steps that would be more precise depth limit. In such case it
is called diameter of the state space.
45
Depth-Limited Search (DLS)
46
Depth-Limited Search (DLS)
Given the following state space (tree search), give the sequence of visited nodes when using DLS
(Limit = 2):
Limit = 0 A
Limit = 1 B C D E
Limit = 2 F G H I J
K L M N
O
© Dr. Tariq 2024 Department of Computer Sciences | Bahria University 47
Depth-Limited Search (DLS)
◼ DLS algorithm returns Failure (no solution)
◼ The reason is that the goal is beyond the limit (Limit =2): the goal depth is (d=4)
depthLimitedSearch(problem)
depth: 2, # of nodes tested: 0, expanded: 0
expnd. node Frontier A
Ø {(A,nil)}
B C D E
F G H I J
Limit = 2
K L M N
F G H I J
Limit = 2
K L M N
F G H I J
Limit = 2
K L M N
Limit = 2
K L M N
Limit = 2
K L M N
Time Complexity
• O(bl)
Space Complexity
• O(bl)
Optimally
• One can view DFS as a special case of the depth DLS, that DFS is DLS with l = infinity.
• DLS is not optimal even if l > d.
DLS can be used when the there is a prior knowledge to the problem, which is always not the case,
Typically, we will not know the depth of the shallowest goal of a problem unless we solved this problem
before.
© Dr. Tariq 2024 Department of Computer Sciences | Bahria University 59
Iterative Deepening Search
Section - 6
Iterative-Deepening Search (IDS)
▪ IDS consists of repeatedly applying limited depth search (DLS), with gradually
increasing limits.
▪ The IDS ends when a solution is found, or if the limited depth search returns
failure, which means there is no solution.
▪ The problem with depth-limited search is deciding on a suitable depth
parameter.
B C D E F
G H I J K L M N O P
Q R S T U V W X Y Z
Completeness
Yes
Time Complexity
O(bd)
Space Complexity
O(bd)
Optimally
Yes, Yes, if step cost = 1 or increasing function of depth
b – maximum branching factor of the search tree
d – depth of the least-cost solution
© Dr. Tariq 2024 Department of Computer Sciences | Bahria University 76
Bidirectional Search
Section - 7
Bidirectional search
Anti-missile system
Search 1 starts from Root node Search 2 starts from Goal node
d/2
Completeness Yes, complete if b is finite, and the state space either has a
solution or is finite
Time Complexity
2*O(bd/2) = O(bd/2)
Space Complexity
O(bd/2)
Optimally
Yes, if both directions are breadth-first or uniform-cost
Uniform Cost 9
D
Goal state reached: ___ States popped off FRONTIER: 2
E 7 G2
What would happen to DFS if S was always visited first?
D E G
O
Z S F
A R
B
P
D
T L M C
© Dr. Tariq 2024 Department of Computer Sciences | Bahria University 89
Uniform Cost Search (UCS)
Find a path from node 1 to the goal node 11. Use UCS method.