Cse-3201 (Ai - 05)
Cse-3201 (Ai - 05)
CSE 3201
Uninformed Search
Uninformed Search
■ Uninform search is also called Blind search. It is the search which has no
information about its domain. The only thing that a blind search can do is to
differentiate between a non goal state and a goal state. These methods do not need
domain knowledge but they are less efficient in result.
■ Uninform strategies don’t use any information about how close a node might be to a
goal. They differ in the order that the nodes are expanded. The most important
uninformed techniques are breadth first search, depth first search, IDDFS, uniform
cost search.
2
Uninformed Search Strategies
■ Use only information available in the problem formulation
-Breadth-first
-Depth-first
-Depth-limited
-Iterative deepening
-Uniform Cost
-Bi-Directional
3
Breadth-First Search
■ Expand shallowest unexpanded node
■ All the nodes reachable from the current node are explored first
– achieved by the TREE-SEARCH method by appending newly generated nodes at the end
of the search queue.
■ Implementation:
– A FIFO queue, i.e., new successors go at end
■ Order of expanding nodes:
4
Breadth-First Snapshot
5
Breadth-First Snapshot
6
Breadth-First Snapshot
7
Breadth-First Snapshot
8
Breadth-First Snapshot
9
Breadth-First Snapshot
10
Breadth-First Snapshot
11
Breadth-First Snapshot
12
Breadth-First Snapshot
13
Breadth-First Snapshot
14
Breadth-First Snapshot
15
Breadth-First Snapshot
16
BFS Tree for Route
17
Pros & Cons of BFS
Pros: Cons:
■ If there is a solution, BFS is ■ Each level of nodes are stored
guaranteed to find it. before creating the next one,
hence it uses more memory.
■ If there are multiple solutions,
then a minimal solution will be ■ If the solution is far away from
found. the root, BFS will consume more
time.
■ BFS will not get trapped during
exploring.
18
Breadth-First Search
19
Breadth-First Search
20
Breadth-First Search
21
Breadth-First Search
22
Breadth-First Search
23
Breadth-First Search
24
Breadth-First Search
25
Breadth-First Search
26
Breadth-First Search
27
Properties of BFS
■ Completeness:
Yes, the solution is reached if it exists.
■ Optimality:
Yes.
28
Properties of BFS
• Time Complexity
– assume (worst case) that there is 1 d=0
goal leaf at G
– so BFS will expand all nodes d=1
d=0
• Space Complexity
– how many nodes can be in the queue
d=1
(worst-case)?
– at depth d-1 there are bd unexpanded d=2
nodes in the Q = O (bd) G
– Nodes are kept in memory.
29
BFS Example
30
Depth-first Search
■ Expand deepest unexpanded node
■ DFS progresses by expanding the first child node of the search tree that appears and thus
going deeper and deeper until a goal node is found, or until it hits a node that has no
children. Then the search backtracks, returning to the most recent node it hasn’t finished
exploring.
■ Implementation:
– A LIFO data structure, i.e., a stack
■ Guarantees to find a solution if the problem space is finite.
– achieved by the TREE-SEARCH method by appending newly generated nodes at the
beginning of stack.
31
Depth-first Search
32
Depth-first Search
33
Depth-first Search
34
Depth-first Search
35
Depth-first Search
36
Depth-first Search
37
Depth-first Search
38
Depth-first Search
39
Pros and Cons of DFS
Pros Cons
■ DFS requires less memory since ■ The disadvantage of Depth-First
only the nodes on the current Search is that there is a
path are stored. possibility that it may go down to
infinite loop when there is a
■ If DFS finds solution without
cycle.
exploring much in a path then
the time and space it takes will ■ Depth-First Search is incomplete
be very less. when the search space is not
finite, thus not guaranteed to
find the solution.
40
Properties of DFS
■ Complete?
No (Yes on finite trees, fails in infinite state space)
■ Optimality:
Consider the scenario that there is more than one goal node, and our search decided to
first expand the left sub tree of the root where there is a solution at a very deep level of
this left sub tree, in the same time the right sub tree of the root has a solution near the
root, here comes the non-optimality of DFS that it is not guaranteed that the first goal to
find is the optimal one, so we conclude that DFS is non-optimal.
41
Properties of DFS
■ Time Complexity
– assume (worst case) that there is 1 goal leaf
at G so, DFS will expand all nodes d=0
=1 + b + b2+ ......... + bd
= O (bd) d=1
– bad if d is much larger than b d=2
■ Space Complexity G
– how many nodes in the stack?
level 1: b-1 nodes d=
0
level 2 : b-1 nodes d=
…. 1
d=
level d-1: b-1 nodes 2
level d: b nodes
d=
■ So, total node in the memory = (b-1)(d-1)+b = bd+1- 3
b+d+b = bd+1-d = (b-1)d+1 === aprroximately
O(bd) space. 42
BFS vs DFS
44
Depth-Limited Search
■ Depth limit of 2 would mean that children of E are ignored.
45
Properties of Depth-Limited Search
• Complete?
Yes if there is a goal state at a depth less than L
• Optimal?
No
• Time Complexity:
O (bL), where L is the cutoff.
• Space Complexity:
O(bL), where L is the cutoff.
46
Iterative Deepening Search or IDDFS
• BFS
– good for optimality
– bad on memory, O(bd)
• DFS
– solutions not guaranteed optimal: dives and misses good nodes
– good for memory O(bd)
• “Iterative Deepening” refers to a method that tries to combine the best of the
above.
47
Iterative Deepening Search
■ To avoid the infinite depth problem of DFS, we can
decide to only search until depth L, i.e. we don’t expand beyond depth L.
That is Depth-Limited Search.
• What if solution is deeper than L? Ans: Increase L iteratively.
48
Iterative Deepening Search L=0
49
Iterative Deepening Search L=1
50
Iterative Deepening Search L=2
51
Iterative Deepening Search L=3
52
Iterative Deepening Search
■ Complete?
Yes
■ Optimal?
Yes
■ Time
O(bd), where d is the depth of the solution.
■ Space
O(bd), where d is the depth of the solution.
53
Search with varying step costs
■ BFS finds the path with the fewest steps, but does not always find the cheapest
path.
54
Uniform-Cost Search(UCS)
55
Uniform-Cost Search
■ At any given point in the execution, the algorithm never expands a node which has a
cost greater than the cost of the shortest path in the tree.
■ First goal found is least-cost solution
56
UCS Example
57
Example for illustrating uninformed search
strategies
S
3 1 8
A B C
3 15
7 20 5
D E G
58
Breadth-First Search
Expanded node Nodes list
S { S0 }
3 1 8 S0 { A3 B1 C8 }
A3 { B1 C8 D6 E10 G18 }
A B C B1 { C8 D6 E10 G18 G21 }
3 15 C8 { D6 E10 G18 G21 G13 }
7 20 5 D6 { E10 G18 G21 G13 }
D E G E10 { G18 G21 G13 }
G18 { G21 G13 }
Solution path found is S A G , cost 18
59
Depth-First Search
Expanded node Nodes list
S { S0 }
3 1 8 S0 { A3 B1 C8 }
A3 { D6 E10 G18 B1 C8 }
A B C D6 { E10 G18 B1 C8 }
3 15 E10 { G18 B1 C8 }
7 20 5 G18 { B1 C8 }
D E G
Solution path found is S A G, cost 18
60
Uniform-Cost Search
Expanded node Nodes list
{ S0 }
S
S0 { B1 A3 C8 }
3 1 8 B1 { A3 C8 G21 }
A3 { D6 C8 E10 G18 G21 }
A B C D6 { C8 E10 G18 G21 }
3 15
7 20 C8 { E10 G13 G18 G21 }
5 E10 { G13 G18 G21 }
D E G G13 { G18 G21 }
Solution path found is S C G, cost 13
61
Exercise
62
Uniform-Cost Search
63
When to use What
• Depth-First Search:
– Many solutions exist
– Know (or have a good estimate of) the depth of solution
• Breadth-First Search:
– Some solutions are known to be shallow
• Uniform-Cost Search:
– Actions have varying costs
– Least cost solution is required
– This is the only uninformed search that worries about costs.
• Iterative-Deepening Search:
– Space is limited and the shortest solution path is required
64
Bi-directional Search
• Alternate searching from the start state toward the goal and from the goal state toward the
start.
• Stop when the frontiers intersect.
• Works well only when there are unique start and goal states and when actions are
reversible.
• Can lead to finding a solution more quickly.
65