Cs221 LEC 3 Slides
Cs221 LEC 3 Slides
Week 3
Search Problems
● Need to define:
○ States
■ Start State
○ Actions
○ Goals
○ Costs
○ Successors
Objective?
2
States
● A state space contains all the possible
configurations of the system.
Goal
11
Backtracking Search
Start
Goal
12
Depth First Search
Start
Goal
13
Depth First Search
Start
Goal
14
Breadth First Search
Start
Goal
15
Breadth First Search
Start
Goal
16
Iterative Deepening Depth First Search
Start
Goal
17
Iterative Deepening Depth First Search
Start
Goal
18
Dynamic Programming
● An algorithm that is akin to backtracking search with memoization and potentially
exponential savings!
● The states in DP contain a summary of past actions sufficient to choose future
actions optimally.
19
Dynamic Programming Example
● Grid Dimensions: The grid dimensions are m (rows) and n (columns)
● Movement Constraints: Wall-E can only move either down or to the right at any given point. It cannot
move diagonally or backwards.
● Problem: find the number of unique paths the Wall-E can take to get home.
20
Dynamic Programming Example
● Nodes: each cell is a node on the graph
● Edges: each edge is a possible path for the robot.
● Ideas and Intuition: ?
21
Dynamic Programming Example
● Ideas and Intuition: use a 2D array to store the number of unique paths to each cell. A cell (i,j) can be
reached either from (i−1,j) or (i,j−1), and thus the number of unique paths to (i,j) is the sum of the
number of unique paths to these two cells.
22
Dynamic Programming Example
● Ideas and Intuition: use a 2D array to store the number of unique paths to each cell. A cell (i,j) can be
reached either from (i−1,j) or (i,j−1), and thus the number of unique paths to (i,j) is the sum of the
number of unique paths to these two cells.
23
Dynamic Programming Example
● Ideas and Intuition: use a 2D array to store the number of unique paths to each cell. A cell (i,j) can be
reached either from (i−1,j) or (i,j−1), and thus the number of unique paths to (i,j) is the sum of the
number of unique paths to these two cells.
24
DP does not work if there are cycles
- DP requires the search tree to be a Directed Acyclic Graph (DAG)
- This is because we need an ordering to fill out the entries in the memo;
otherwise, we would not know where to start!
Bad
Uniform Cost Search
Explored
Frontier
Unexplored
Uniform Cost Search
UCS - Pseudocode (from lecture slides)
UCS - Proof of Correctness
UCS - Proof of Correctness
UCS - Proof of Correctness
UCS - Proof of Correctness
Contradiction!
UCS does not work if there are negative edges
Middle
- Optimal: start -> middle -> end with a cost of -5
5 -10 - UCS finds: start -> end with a cost of 1
- Always try to come up with your own examples
- The simpler the example, the better!
Start End
1
Problem (1a)
● Describe A:
● s =
start
● Actions((x,y,A)) = {N,S,E,W}
● Succ((x,y,A),a) =
● Cost((x,y,A),a) =
● IsGoal((x,y,A)) =
34
Problem (1b)
35
Looking Ahead: Heuristics
36
A*: UCS with heuristics
- A* is an expansion of UCS, but we use an estimate of “future cost”
- This should give us a better estimate of total cost to END = past cost + future cost
- Leads to more efficient search!
- If the new costs are non-negative, UCS would return the correct result
Problem (1c)
39
Problem (2a)
40
Problem (2b)
41
Thank You
42
Come to our office hours!
General OH: Thursdays 2:00-4:00 Online HW OH: Tuesdays 9am to 1pm Huang Basement
HW OH: Tuesdays 2:00-4:00 Online
43