Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views236 pages

PS - 01 Uninformed Search

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views236 pages

PS - 01 Uninformed Search

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 236

Uninformed Search

(Blind Search)
Boris Velichkov
Exercises by Week
1. Introduction
2. Uninformed (Blind) Search
3. Informed (Heuristic) Search
4. Constraint Satisfaction Problems
5. Genetic Algorithms
6. Games
7. Introduction to Machine Learning
8. k-Nearest Neighbors
9. Naïve Bayes Classifier
10. Decision Tree
11. kMeans
12. Neural Networks
13. Additional Topics, Questions and Homeworks' Presentations
14. Additional Topics, Questions and Homeworks' Presentations
15. Additional Topics, Questions and Homeworks' Presentations
Problem Solving and Search
• Basic Concepts
– State Space
– Representation of the State Space
– Search Strategies Evaluation
– Global Search vs Local Search
– Uninformed Search vs Informed Search
– Graph and Tree Traversal
State Space
• State: a representation (formulation) of the task in the
process of its solution.
– Initial State (presented with S)
– Intermediate State (presented with any capital letter except S
and G)
– Goal State (presented with G, if there are more: G1, G2, etc.)
• Successor Function (Operator): obtaining one state from
another
• Path Cost: additive; e.g., sum of distances, number of
actions executed, etc.
• State Space: the totality of all possible states that can be
obtained from a given initial state.
* A solution is a sequence of actions leading from the initial state to a goal state
Representation of the State Space
• Graph or Tree where each state is represented
with Node and the successor function
(operator) is represented with Edge.
• When the state space can be represented as a
tree, it is called Search Tree.
– The initial state is the root of the tree.
– The terminal states and the goal state are
represented with leaves.
Search Strategies Evaluation
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/expanded
• Space Complexity: maximum number of nodes in memory
* We look at the worst-case complexity (Big O notation).

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 ∞)
Search Strategies Evaluation
0------------------------ S b=3
d=2
m=3
1---------- A B C

2---- D E F G2

3- G1
Global Search vs Local Search
• Global Search: They look all over the state
space. If necessary, all states will be traversed.
• Local Search: They only look at the local area,
so they can only look at states in this area. If
the solution is outside of it, they will not be
able to find it.

* Generally Local Search is not used for finding a path from state
A to state B.
Local Search
• Local Search in Artificial Intelligence is an optimizing
algorithm to find the optimal solution more quickly.
• Local search algorithms are used when we care only about
a solution but not the path to a solution.
• Local search is a heuristic method for solving
computationally hard optimization problems.
• Local search can be used on problems that can be
formulated as finding a solution maximizing a criterion
among a number of candidate solutions.
• Local search algorithms move from solution to solution in
the space of candidate solutions (the search space) by
applying local changes, until a solution deemed optimal is
found or a time bound is elapsed.
Uninformed (Blind) Search vs
Informed (Heuristic) Search
• Uninformed Search: Uninformed strategies use
only the information available in the problem
definition.
– Examples: DFS, BFS, UCS, DLS, IDS.
• Informed Search: Informed strategies have
information on the goal state which helps in
more efficient searching. This information is
obtained by a function (heuristic) that estimates
how close a state is to the goal state.
– Examples: Greedy Best-First Search, A*, Beam Search,
Hill Climbing.
Graph and Tree Traversal
• Node: The graphs and trees consist of nodes and edges. When a
node is neither “visited” nor “expanded”, we do not mark it in any
way (sits uncolored).
– Example:
S
• Visited Node: When we visit a node or in other words add it to the
data structure we use we call it “visited node”. We mark it in blue.
– Example:
S
• Expanded Node: When we expand a node or in other words
remove it from the data structure we use and add its children in this
data structure (of course if the node has children) we call it
“expanded node”. We mark it in red.
– Example:
S
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: DFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: BFS
S

A B

C D E F

G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Graph and Tree Traversal: BFS
0------------------------ S

1---------- A B

2---- C D E F

3- G H I J K L M N
Uninformed (Blind) Search
• “Uninformed strategies use only the
information available in the problem
definition.”
• Uninformed Search Algorithms:
– Depth-First Search (DFS)
– Breadth-First Search (BFS)
– Uniform-Cost Search (UCS)
– Depth-Limited Search (DLS)
– Iterative Deepening Search (IDS)
Depth-First Search
A

B S Visited Nodes:
{}

C G
Legend:

D F S Node

S Visited Node

E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A}

C G
Legend:

D F S Node

S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B}

C G
Legend:

D F S Node
B
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A
B
B S Visited Nodes:
{A,B}

C G
Legend:

D F S Node

S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B}

C G
Legend:

D F S Node

S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S}

C G
Legend:

D F S Node
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S,C}

C G
Legend:
C S Node
D F
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S,C,D}

C G D Legend:
C S Node
D F
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S,C,D}

C G
Legend:
C S Node
D F
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S,C,D,E}

C G E Legend:
C S Node
D F
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S,C,D,E,H}
H
C G E Legend:
C S Node
D F
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

G
B S Visited Nodes:
{A,B,S,C,D,E,H,G}
H
C G E Legend:
C S Node
D F
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A F
G
B S Visited Nodes:
{A,B,S,C,D,E,H,G,F}
H
C G E Legend:
C S Node
D F
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

G
B S Visited Nodes:
{A,B,S,C,D,E,H,G,F}
H
C G E Legend:
C S Node
D F
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S,C,D,E,H,G,F}
H
C G E Legend:
C S Node
D F
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S,C,D,E,H,G,F}

C G E Legend:
C S Node
D F
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S,C,D,E,H,G,F}

C G
Legend:
C S Node
D F
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S,C,D,E,H,G,F}

C G
Legend:

D F S Node
S
S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S,C,D,E,H,G,F}

C G
Legend:

D F S Node

S Visited Node
A
E H Stack (FILO)
S Expanded Node
Depth-First Search
A

B S Visited Nodes:
{A,B,S,C,D,E,H,G,F}

C G
Legend:

D F S Node

S Visited Node

E H Stack (FILO)
S Expanded Node
Depth-First Search (DFS)
• Complete?
– No: fails in infinite-depth spaces, spaces with loops
Modify to avoid repeated states along path
⇒ complete in finite spaces
• Optimal?
– No
• Time?
– O(bm): terrible if m is much larger than d
but if solutions are dense, may be much faster than
breadth-first
• Space?
– O(bm), i.e., linear space!
* A dense graph is a graph in which the number of edges is close to the
maximal number of edges.
Breadth-First Search
A

B S Visited Nodes:
{}

C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A

B S Visited Nodes:
{A}

C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A

B S Visited Nodes:
{A}

C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A
B
B S S Visited Nodes:
{A,B,S}

C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A
S
B S Visited Nodes:
{A,B,S}

C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A

B S Visited Nodes:
{A,B,S}

C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A
C
B S G Visited Nodes:
{A,B,S,C,G}

C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A
G
B S Visited Nodes:
{A,B,S,C,G}

C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A
G
B S D Visited Nodes:
{A,B,S,C,G,D,E,F}
E
C G
F Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A
D
B S E Visited Nodes:
{A,B,S,C,G,D,E,F}
F
C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A
D
B S E Visited Nodes:
{A,B,S,C,G,D,E,F,H}
F
C G
H Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A
E
B S F Visited Nodes:
{A,B,S,C,G,D,E,F,H}
H
C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A
F
B S H Visited Nodes:
{A,B,S,C,G,D,E,F,H}

C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A
H
B S Visited Nodes:
{A,B,S,C,G,D,E,F,H}

C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search
A

B S Visited Nodes:
{A,B,S,C,G,D,E,F,H}

C G
Legend:

D F S Node

S Visited Node

E H Queue (FIFO)
S Expanded Node
Breadth-First Search

Node {
Node parent
T value
List<Node> children
}
Breadth-First Search (BFS)
• Complete?
– Yes (if b is finite)
• Optimal?
– Yes (if cost = 1 per step); not optimal in general
• Time?
– 1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd+1), i.e., exp.
in d
• Space?
– O(bd+1) (keeps every node in memory)
* Space is the big problem; can easily generate nodes at 100MB/sec so
24hrs = 8640GB.
Uniform-Cost Search

9 G Visited Nodes:
C 6
{}
2

14
11 D
B Legend:
9
15
S Node
10
S
S Visited Node
7
A S Expanded Node
Uniform-Cost Search

9 G Visited Nodes:
C 6
{}
2

14
11 D
B Legend:
9
15
S Node
10
S
S Visited Node
7
A S Expanded Node
Uniform-Cost Search

9 G Visited Nodes:
C 6
{}
2

14
11 D
B Legend:
9
15
S Node
10
S
S Visited Node
7
A S Expanded Node
Uniform-Cost Search

9 G Visited Nodes:
C 6
{S}
2

14
11 D
B Legend:
9
(0) 15
S Node
10
S
S Visited Node
7
A S Expanded Node
Uniform-Cost Search

9 G Visited Nodes:
C 6
{S}
2

14
11 D
B Legend:
9
(0) 15
S Node
10
S
S Visited Node
7
A S Expanded Node
Uniform-Cost Search

(14)
9 G Visited Nodes:
C 6
{S,A,B,C}
2
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search

(14)
9 G Visited Nodes:
C 6
{S,A,B,C}
2
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search

(14)
9 G Visited Nodes:
C 6
{S,A,B,C,D}
2 (22)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search

(14)
9 G Visited Nodes:
C 6
{S,A,B,C,D}
2 (22)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7 9<17
A S Expanded Node
Uniform-Cost Search

(14)
9 G Visited Nodes:
C 6
{S,A,B,C,D}
2 (22)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search

(14)
9 G Visited Nodes:
C 6
{S,A,B,C,D}
2 (22)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search
14>11
22>20
(14)
9 G Visited Nodes:
C 6
{S,A,B,C,D}
2 (22)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search

(11)
9 G Visited Nodes:
C 6
{S,A,B,C,D}
2 (20)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search

(11)
9 G Visited Nodes:
C 6
{S,A,B,C,D}
2 (20)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search
(20)
(11)
9 G Visited Nodes:
C 6
{S,A,B,C,D,G}
2 (20)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search
(20)
(11)
9 G Visited Nodes:
C 6
{S,A,B,C,D,G}
2 (20)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search
(20)
20<26
(11)
9 G Visited Nodes:
C 6
{S,A,B,C,D,G}
2 (20)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search
(20)
(11)
9 G Visited Nodes:
C 6
{S,A,B,C,D,G}
2 (20)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search
(20)
(11)
9 G Visited Nodes:
C 6
{S,A,B,C,D,G}
2 (20)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search
(20)
(11)
9 G Visited Nodes:
C 6
{S,A,B,C,D,G}
2 (20)
(9)
14
11 D
B Legend:
9
(0) 15
S Node
10
S
(7)
S Visited Node
7
A S Expanded Node
Uniform-Cost Search (UCS)
• Complete?
– Yes, if step cost ≥ ε
• Optimal?
– Yes - nodes expanded in increasing order of g(n)
• Time?
– # of nodes with g ≤ cost of optimal solution, O(b⌈C*/ε⌉)
where C* is the cost of the optimal solution
• Space?
– # of nodes with g ≤ cost of optimal solution, O(b⌈C*/ε⌉)
* Expand least-cost unexpanded node using queue ordered by path cost, lowest first
* Equivalent to breadth-first if step costs all equal
Depth-Limited Search
• = depth-first search with depth limit l,
i.e., nodes at depth l have no successors
• Also known as Depth-Bounded Search
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Depth-Limited Search (DLS)
“DLS = depth-first search with depth limit l, i.e., nodes at
depth l have no successors”
• Complete?
– Yes, if l ≥ d
• Optimal?
– No
• Time?
– O(bl)
• Space?
– O(bl)
* DLS searches in a subspace (local area), but it is NOT a local search
algorithm!
Iterative Deepening Search (IDS)
Iterative Deepening Search
0------------------------ S 𝒍=𝟎

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟎

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟎

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟎

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟏

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟏

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟏

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟏

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟏

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟏

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟏

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟏

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟏

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟐

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search
0------------------------ S 𝒍=𝟑

1---------- A B

2---- C D E F

3- G H I J K L M N
Iterative Deepening Search (IDS)
• Complete?
– Yes
• Optimal?
– Yes, if step cost = 1 (Can be modified to explore
uniform-cost tree)
• Time?
– (d + 1)b0 + db1 + (d − 1)b2 + . . . + bd = O(bd)
• Space?
– O(bd), i.e., linear space!
Iterative Deepening Search (IDS)
Numerical comparison for b = 10 and d = 5, solution at far
right leaf:

N(IDS) = 50 + 400 + 3, 000 + 20, 000 + 100, 000 = 123, 450

N(BFS) = 10 + 100 + 1, 000 + 10, 000 + 100, 000 + 999, 990 = 1, 111, 100

* IDS does better because other nodes at depth d are not expanded
* BFS can be modified to apply goal test when a node is generated
Summary of Algorithms

Criterion DFS BFS UCS DLS IDS


Complete No Yes* Yes* Yes* Yes
(if b is finite) (if step cost ≥ ε) (if l ≥ d)
Time bm bd+1 b⌈C*/ℇ⌉ bl bd
Space bm bd+1 b⌈C*/ℇ⌉ bl bd
Optimal No Yes* Yes No Yes*
(if step cost = 1) (if step cost = 1)
Data Priority
Stack Queue Stack Stack
Structure Queue
Homework: “Frog Leap Puzzle”
• The game has 2N + 1 fields of play. In the beginning of the
game there are N frogs which are looking to the left and
placed on the rightmost N fields, and N frogs which are
looking to the right and placed on the leftmost fields. The
aim of the game is to swap the places of the frogs and
reach the opposite configuration.
• The rules of play are as follows: Each frog can only move in
the direction it looks at. Every frog can jump in a free field
in front of it or jump over a frog to go to an empty field in
front of it.
• Input: N - number of frogs looking in one direction
• Output: All the configurations that needed to go through to
get from the start to the final state.
Homework: “Frog Leap Puzzle”
• Sample Input:
2

• Sample Output:
>>_<<
>_><<
><>_<
><><_
><_<>
_<><>
<_><>
<<>_>
<<_>>
Frog Leap Puzzle
• How can we solve the problem?
• Can we solve the problem using uninformed
search algorithm?
– If “Yes”, how can we represent the puzzle as a tree
or a graph?
– Which uninformed search algorithm is best? Why?
• Can we solve the problem in a better way?
• What about a linear time solution?
Frog Leap Puzzle
• Initial State: LL_RR
• Successor Function (moves):
– Left moves (only R)
• Jump: LL_RR → LLR_R
• Double Jump: LL_RR → LLRR_
– Right moves (only L)
• Jump: LL_RR → L_LRR
• Double Jump: LL_RR → _LLRR
• Goal State: RR_LL
Frog Leap Puzzle
Frog Leap Puzzle
n = readInput();
size = (n * 2) + 1;
board = new board[size];
function dfs(board, zeroState) {
if isGoalState(board, zeroState)
return TRUE;
for move in moves(board, zeroState) {
if dfs(move.board, move.zeroState) {
print(move.board);
return TRUE;
}
}
return FALSE;
}

You might also like