Lec 3-Solving Problems by Searching Part 1 (2)
Lec 3-Solving Problems by Searching Part 1 (2)
LECTURE 3:
SOLVING PROBLEMS BY
SEARCHING PART 1
2024
Objective
Problem-solving agents
Problem formulation
Example problems
Search Tree
Uninformed Search
Problem-Solving Agents
Goal formulation :
be in Bucharest
Problem formulation :
states: various cities
actions: drive between cities or choose next city
Find solution:
sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
Well-defined Problems and Solution
A problem consists of five parts:
1. State space: A set of possible states that the environment
can be in
2. The initial state that the agent starts in.
3. A set of actions
4. A transition model describing the results of those actions
5. A goal states
6. A path cost function.
The environment of the problem is represented by a state
space.
A path through the state space from the initial state to a
goal state is a solution.
Example: Romania
On vacation in Romania;
currently in Arad. Flight leaves
tomorrow from Bucharest
States?
Initial state ?
Actions ?
Transition model?
goal states ?
path cost ?
Vacuum world state space graph
States ?
Initial state ?
Actions ?
Transition model?
Goal states ?
Path cost ?
Example: The 8-puzzle
The agent must find a sequence of actions that reaches the goal
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Goal is H A
In
Frontier
(To be visited) B C
Out
D E F G
Visited Set = ()
H I
1. Breadth-First Search
Goal is H A
In
Frontier
(To be visited) B C
A
Out
D E F G
POP
Visited Set = ()
H I
1. Breadth-First Search (BFS)
Goal is H A
In
Frontier
(To be visited) B C
C, B
POP Out
D E F G
Goal is H A
In
Frontier
(To be visited) B C
F, E, D, C
Out
POP D E F G
Goal is H A
In
Frontier
(To be visited) B C
G, F, E, D
Out
POP D E F G
Goal is H A
In
Frontier
(To be visited) B C
G, F, E
Out
POP D E F G
Goal is H A
In
Frontier
(To be visited) B C
G, F
Out
POP D E F G
Goal is H A
In
Frontier
(To be visited) B C
H, G
Out
POP D E F G
Goal is H A
In
Frontier
(To be visited) B C
I, H
Out
POP D E F G
Goal is H A
In
Frontier
(To be visited) B C
I
Out
DONE D E F G
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Advantages
Disadvantages
d
Time complexity and space complexity are both O( b ). This is a
very big hurdle.
Goal is H A
In
Frontier
(To be visited) B G
Out C D E H
Visited Set = ()
F I
2. Depth-First Search (DFS)
Goal is H A
In
Frontier
(To be visited) B G
A
Out
POP C D E H
Visited Set = ()
F I
2. Depth-First Search (DFS)
Goal is H A
In
Frontier
(To be visited) B G
B,G
Out
POP C D E H
Goal is H A
In
Frontier
(To be visited) B G
C, D, E , G
Out
POP C D E H
Goal is H A
In
Frontier
(To be visited) B G
D, E , G
Out
POP C D E H
Goal is H A
In
Frontier
(To be visited) B G
E,G
Out
POP C D E H
Goal is H A
In
Frontier
(To be visited) B G
F,G
Out
POP C D E H
Goal is H A
In
Frontier
(To be visited) B G
G
Out
POP C D E H
Goal is H A
In
Frontier
(To be visited) B G
H
Out
POP C D E H
Goal is H A
In
Frontier
(To be visited) B G
I
Out
DONE C D E H
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
Arad
Rimnicu
Arad Fagaras Oradea Arad Lugoj Arad Orade
Vilcea
B C
Complete? No because may fail in infinite-depth spaces
Can modify to avoid repeated states along path
Time? O(bm) with m=maximum depth
terrible if m is much larger than d
Space? O(bm), i.e., linear space! (we only need to
remember a single path + expanded unexplored nodes)
Optimal? No (It may find a non-optimal goal first)
b: maximum branching factor of the search tree (the number of children that a node can have)
d: depth of the least-cost solution
m: maximum depth of the state space (may be ∞)
Properties of Depth-First Search
Advantages
Memory requirements are less because only nodes on the current path
are stored
Disadvantages
This type can go on and on, deeper and deeper into the search
space and thus, we can get lost. This is referred to blind alley.
BFS Vs. DFS
BFS DFS
Complete? YES NO
Time O(bd) O(bm)
Space O(bd) O(bm)
Optimal? YES NO
b: maximum branching factor of the search tree (the number of children that a node can have)
d: depth of the least-cost solution
m: maximum depth of the state space (may be ∞)
3. Iterative Deepening Search IDS
Goal is M A
BFS ?
DFS?
IDS? B C
D E F G
H I J K L M N O
3. Iterative Deepening Search (l =0)
3. Iterative Deepening Search (l =1)
3. Iterative Deepening Search (l =2)
3. Iterative Deepening Search (l =3)
BFS Vs. DFS Vs. IDS
b: maximum branching factor of the search tree (the number of children that a node can have)
d: depth of the least-cost solution
m: maximum depth of the state space (may be ∞)
Advantages & Disadvantages of IDS
Advantages
It is guaranteed to find a shortest path solution.
It is a preferred uninformed search method when the search space
is large and the depth of solution is not known.
Disadvantages
It performs wasted computations before reaching to the goal
depth.
Summary
Uninformed Search Strategies
1. Breadth-first search
2. Uniform-cost search
3. Depth-first search
4. Depth-limited search
5. Iterative deepening sear