106
Graph Search Chris Amato Northeastern University Some images and slides are used from: Rob Platt, CS188 UC Berkeley, AIMA

Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Graph Search Chris Amato Northeastern University Some images and slides are used from: Rob Platt, CS188 UC Berkeley, AIMA

Page 2: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

What is graph search?

Graph search: find a path from start to goal

– what are the states?

– what are the actions (transitions)?

– how is this a graph?

Start state Goal state

Page 3: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

What is graph search?

Graph search: find a path from start to goal

– what are the states?

– what are the actions (transitions)?

– how is this a graph?

Start state Goal state

Page 4: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

What is graph search?

Graph search: find a path from start to goal

– what are the states?

– what are the actions (transitions)?

– how is this a graph?

Start state

Goal state

Page 5: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

What is graph search?

Graph search: find a path from start to goal

– what are the states?

– what are the actions (transitions)?

– how is this a graph?

Start state

Goal state

Page 6: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

What is a graph?

Graph:

Edges:

Vertices:

Directed graph

Page 7: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

What is a graph?

Graph:

Edges:

Vertices:

Undirected graph

Page 8: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

What is a graph?

Graph:

Edges:

Vertices: Also called states

Also called transitions

Page 9: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Defining a graph: example

Page 10: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Defining a graph: example

How many states?

Page 11: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Defining a graph: example

Page 12: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Defining a graph: example

Pairs of states that are “connected” by one turn of the cube.

Page 13: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Example: Romania

l  On holiday in Romania; currently in Arad. Flight leaves tomorrow from Bucharest

l  Formulate goal: Be in Bucharest

l  Formulate problem: l  states: various cities l  actions: drive between cities

l  Find solution: l  sequence of cities, e.g., Arad,

Sibiu, Fagaras, Bucharest

Page 14: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Graph search

Given: a graph, G

Problem: find a path from A to B

– A: start state

– B: goal state

Page 15: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Graph search

Given: a graph, G

Problem: find a path from A to B

– A: start state

– B: goal state

How?

Page 16: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Problem formulation

A problem is defined by four items:

l  initial state e.g., “at Arad”

l  successor function S(x) = set of action–state pairs

e.g., S(Arad) = {⟨Arad → Zerind, Zerind⟩, . . .}

l  goal test, can be explicit, e.g., x = “at Bucharest” implicit, e.g., NoDirt(x)

l  path cost (additive)

e.g., sum of distances, number of actions executed, etc. c(x, a, y) is the step cost, assumed to be ≥ 0

l  A solution is a sequence of actions leading from the initial state to a goal state

Page 17: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

A search tree

Start at A

Page 18: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

A search tree

Successors of A

Page 19: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

A search tree

Successors of A

parent children

Page 20: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

A search tree

Let's expand S next

Page 21: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

A search tree

Successors of S

Page 22: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

A search tree

A was already visited!

Page 23: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

A search tree

A was already visited! So, prune it!

Page 24: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

A search tree

In what order should we expand states?

– here, we expanded S, but we could also have expanded Z or T

– different search algorithms expand in different orders

Page 25: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

Page 26: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

Page 27: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

Start node

Page 28: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

Page 29: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

Page 30: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

Page 31: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

We're going to maintain a queue called the fringe – initialize the fringe as an empty queue

Fringe

Page 32: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

– add A to the fringe

fringe Fringe A

Page 33: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

-- remove A from the fringe -- add successors of A to the fringe

fringe

Fringe B C

Page 34: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

-- remove B from the fringe -- add successors of B to the fringe

fringe

Fringe C D E

Page 35: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

fringe

Fringe D E F G

-- remove C from the fringe -- add successors of C to the fringe

Page 36: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

fringe

Fringe D E F G

Which state gets removed next from the fringe?

Page 37: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

fringe

Fringe D E F G

Which state gets removed next from the fringe? What kind of a queue is this?

Page 38: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

fringe

Fringe D E F G

Which state gets removed next from the fringe? What kind of a queue is this?

FIFO Queue! (first in first out)

Page 39: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

Page 40: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Breadth first search (BFS)

What is the purpose of the explored set?

Page 41: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

BFS Properties

Is BFS complete? – is it guaranteed to find a solution if one exists?

Page 42: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

BFS Properties

Is BFS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of BFS? – how many states are expanded before finding a sol'n?

– b: branching factor – d: depth of shallowest solution – complexity = ???

Page 43: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

BFS Properties

Is BFS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of BFS? – how many states are expanded before finding a solution?

– b: branching factor – d: depth of shallowest solution – complexity =

Page 44: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

BFS Properties

Is BFS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of BFS? – how many states are expanded before finding a solution?

– b: branching factor – d: depth of shallowest solution – complexity =

What is the space complexity of BFS? – how much memory is required?

– complexity = ???

Page 45: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

BFS Properties

Is BFS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of BFS? – how many states are expanded before finding a solution?

– b: branching factor – d: depth of shallowest solution – complexity =

What is the space complexity of BFS? – how much memory is required?

– complexity =

Page 46: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

BFS Properties

Is BFS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of BFS? – how many states are expanded before finding a solution?

– b: branching factor – d: depth of shallowest solution – complexity =

What is the space complexity of BFS? – how much memory is required?

– complexity = Is BFS optimal? – is it guaranteed to find the best solution (shortest path)?

Page 47: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Page 48: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Notice the distances between cities

Page 49: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Notice the distances between cities – does BFS take these distances into account?

Page 50: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Notice the distances between cities – does BFS take these distances into account? – does BFS find the path w/ shortest milage?

Page 51: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Notice the distances between cities – does BFS take these distances into account? – does BFS find the path w/ shortest milage? – compare S-F-B with S-R-P-B. Which costs less?

Page 52: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Notice the distances between cities – does BFS take these distances into account? – does BFS find the path w/ shortest milage? – compare S-F-B with S-R-P-B. Which costs less?

How do we fix this?

Page 53: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Notice the distances between cities – does BFS take these distances into account? – does BFS find the path w/ shortest milage? – compare S-F-B with S-R-P-B. Which costs less?

How do we fix this? UCS!

Page 54: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Same as BFS except: expand node w/ smallest path cost

Length of path

Page 55: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Same as BFS except: expand node w/ smallest path cost

Length of path

Cost of going from state A to B:

Minimum cost of path going from start state to B:

Page 56: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Same as BFS except: expand node w/ smallest path cost

Length of path

Cost of going from state A to B:

Minimum cost of path going from start state to B:

BFS: expands states in order of hops from start UCS: expands states in order of

Page 57: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Same as BFS except: expand node w/ smallest path cost

Length of path

Cost of going from state A to B:

Minimum cost of path going from start state to B:

BFS: expands states in order of hops from start UCS: expands states in order of How?

Page 58: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Simple answer: change the FIFO to a priority queue – the priority of each element in the queue is its path cost.

Page 59: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Uniform Cost Search (UCS)

Page 60: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

Fringe A

Path Cost 0

Explored set:

Page 61: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

140 118 75

Explored set: A

Fringe A S T Z

Path Cost 0 140 118 75

Page 62: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

140 118 75

146

Explored set: A, Z

Fringe A S T Z T

Path Cost 0 140 118 75 146

Page 63: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

140 118 75

146 229

Explored set: A, Z, T

Fringe A S T Z T L

Path Cost 0 140 118 75 146 229

Page 64: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

140 118 75

239 220 146 229

Explored set: A, Z, T, S

Fringe A S T Z T L F R

Path Cost 0 140 118 75 146 229 239 220

Page 65: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

140 118 75

239 220 146 229

Explored set: A, Z, T, S

Fringe A S T Z T L F R

Path Cost 0 140 118 75 146 229 239 220

Page 66: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

140 118 75

239 220

336 317

146 229

Explored set: A, Z, T, S, R

Fringe A S T Z T L F R C P

Path Cost 0 140 118 75 146 229 239 220 336 317

Page 67: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

140 118 75

239 220

336 317

146 229

299

Explored set: A, Z, T, S, R, L

Fringe A S T Z T L F R C P M

Path Cost 0 140 118 75 146 229 239 220 336 317 299

Page 68: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

140 118 75

239 220

336 317

146 229

299

Explored set: A, Z, T, S, R, L

Fringe A S T Z T L F R C P M

Path Cost 0 140 118 75 146 229 239 220 336 317 299

When does this end?

Page 69: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

140 118 75

239 220

336 317

146 229

299

Explored set: A, Z, T, S, R, L

Fringe A S T Z T L F R C P M

Path Cost 0 140 118 75 146 229 239 220 336 317 299

When does this end? – when the goal state is removed from the queue

Page 70: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

140 118 75

239 220

336 317

146 229

299

Explored set: A, Z, T, S, R, L

Fringe A S T Z T L F R C P M

Path Cost 0 140 118 75 146 229 239 220 336 317 299

When does this end? – when the goal state is removed from the queue

– NOT when the goal state is expanded

Page 71: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS

Page 72: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS Properties

Is UCS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of UCS? – how many states are expanded before finding a solution?

– b: branching factor – C*: cost of optimal solution – e: min one-step cost – complexity =

What is the space complexity of BFS? – how much memory is required?

– complexity = Is BFS optimal? – is it guaranteed to find the best solution (shortest path)?

Page 73: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Strategy: expand cheapest node first:

Fringe is a priority queue (priority: cumulative cost)

UCS vs BFS

S

a

b

d p

a

c

e

p

h

f

r

q

q c G

a

q e

p

h

f

r

q

q c G

a

3 9 1

16 4 11

5

7 13

8

10 11

17 11

0

6 Cost contours

Page 74: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS vs BFS

S

a

b

d p

a

c

e

p

h

f

r

q

q c G

a

q e

p

h

f

r

q

q c G

a

Search

Tiers

Strategy:expandashallowestnodefirst

Implementa6on:FringeisaFIFOqueue

Page 75: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

UCS vs BFS

Remember: UCS explores increasing cost contours

The good: UCS is complete and optimal!

The bad: Explores options in every “direction” No information about goal location

We’ll fix that soon!

Start Goal

c3 c2

c1

Page 76: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Depth First Search (DFS)

Page 77: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS

fringe Fringe A

Page 78: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS

fringe

Fringe A B C

Page 79: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS

fringe

Fringe A B C F G

Page 80: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS

Fringe A B C F G H I

Page 81: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS

Fringe A B C F G H I

Which state gets removed next from the fringe?

Page 82: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS

Fringe A B C F G H I

Which state gets removed next from the fringe? What kind of a queue is this?

Page 83: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS

Fringe A B C F G H I

Which state gets removed next from the fringe? What kind of a queue is this? LIFO Queue!

(last in first out)

Page 84: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Deep/Shallow Water --- DFS, BFS, or UCS? (part 1)

Page 85: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Deep/Shallow Water --- DFS, BFS, or UCS? (part 2)

Page 86: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

Deep/Shallow Water --- DFS, BFS, or UCS? (part 3)

Page 87: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS Properties: Graph search version

Is DFS complete? – only if you track the explored set in memory What is the time complexity of DFS (graph version)? – how many states are expanded before finding a solution?

– complexity = number of states in the graph What is the space complexity of DFS (graph version)? – how much memory is required?

– complexity = number of states in the graph Is DFS optimal? – is it guaranteed to find the best solution (shortest path)?

This is the “graph search” version of the algorithm

Page 88: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS Properties: Graph search version

Is DFS complete? – only if you track the explored set in memory What is the time complexity of DFS (graph version)? – how many states are expanded before finding a solution?

– complexity = number of states in the graph What is the space complexity of DFS (graph version)? – how much memory is required?

– complexity = number of states in the graph Is DFS optimal? – is it guaranteed to find the best solution (shortest path)?

This is the “graph search” version of the algorithm

So why would we ever use this algorithm?

Page 89: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS: Tree search version

Suppose you don't track the explored set. – why wouldn't you want to do that?

This is the “tree search” version of the algorithm

Page 90: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS: Tree search version

Suppose you don't track the explored set. – why wouldn't you want to do that?

This is the “tree search” version of the algorithm

What is the space complexity of DFS (tree version)? – how much memory is required?

– b: branching factor – m: maximum depth of any node – complexity =

Page 91: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS: Tree search version

Suppose you don't track the explored set. – why wouldn't you want to do that?

This is the “tree search” version of the algorithm

What is the space complexity of DFS (tree version)? – how much memory is required?

– b: branching factor – m: maximum depth of any node – complexity =

This is why we might want to use DFS

Page 92: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS: Tree search version

Suppose you don't track the explored set. – why wouldn't you want to do that?

This is the “tree search” version of the algorithm

What is the space complexity of DFS (tree version)? – how much memory is required?

– b: branching factor – m: maximum depth of any node – complexity =

What is the time complexity of DFS (tree version)? – how many states are expanded before finding a solution?

– complexity =

Page 93: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS: Tree search version

Suppose you don't track the explored set. – why wouldn't you want to do that?

This is the “tree search” version of the algorithm

What is the space complexity of DFS (tree version)? – how much memory is required?

– b: branching factor – m: maximum depth of any node – complexity =

What is the time complexity of DFS (tree version)? – how many states are expanded before finding a solution?

– complexity = Is it complete?

Page 94: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS: Tree search version

Suppose you don't track the explored set. – why wouldn't you want to do that?

This is the “tree search” version of the algorithm

What is the space complexity of DFS (tree version)? – how much memory is required?

– b: branching factor – m: maximum depth of any node – complexity =

What is the time complexity of DFS (tree version)? – how many states are expanded before finding a solution?

– complexity = Is it complete? NO!

Page 95: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

DFS: Tree search version

Suppose you don't track the explored set. – why wouldn't you want to do that?

This is the “tree search” version of the algorithm

What is the space complexity of DFS (tree version)? – how much memory is required?

– b: branching factor – m: maximum depth of any node – complexity =

What is the time complexity of DFS (tree version)? – how many states are expanded before finding a solution?

– complexity = Is it complete? NO!

What do we do???

Page 96: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

IDS: Iterative deepening search

What is IDS? – do depth-limited DFS in stages, increasing the maximum depth at each stage

Page 97: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

IDS: Iterative deepening search

What is IDS? – do depth-limited DFS in stages, increasing the maximum depth at each stage What is depth limited search? – any guesses?

Page 98: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

IDS: Iterative deepening search

What is IDS? – do depth-limited DFS in stages, increasing the maximum depth at each stage What is depth limited search? – do DFS up to a certain pre-specified depth

Page 99: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

IDS: Iterative deepening search

§  Idea:getDFS’sspaceadvantagewithBFS’s6me/shallow-solu6onadvantages§  RunaDFSwithdepthlimit1.Ifnosolu6on…

§  RunaDFSwithdepthlimit2.Ifnosolu6on…

§  RunaDFSwithdepthlimit3.…..

§  Isn’tthatwastefullyredundant?§  Generallymostworkhappensinthelowestlevelsearched,sonotsobad!

Page 100: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

IDS

Page 101: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

IDS

What is the space complexity of IDS (tree version)? – how much memory is required?

– b: branching factor – m: maximum depth of any node – complexity =

What is the time complexity of DFS (tree version)? – how many states are expanded before finding a solution?

– complexity = Is it complete?

Page 102: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

IDS

What is the space complexity of IDS (tree version)? – how much memory is required?

– b: branching factor – m: maximum depth of any node – complexity =

What is the time complexity of DFS (tree version)? – how many states are expanded before finding a solution?

– complexity = Is it complete? YES!!! Is it optimal?

Page 103: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

IDS

What is the space complexity of IDS (tree version)? – how much memory is required?

– b: branching factor – m: maximum depth of any node – complexity =

What is the time complexity of DFS (tree version)? – how many states are expanded before finding a solution?

– complexity = Is it complete? YES!!! Is it optimal? YES!!!

Page 104: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

TheOneQueue

§  Allthesesearchalgorithmsarethesameexceptforfringestrategies§  Conceptually,allfringesarepriorityqueues(i.e.collec6onsofnodeswithaTachedpriori6es)

§  Prac6cally,forDFSandBFS,youcanavoidthelog(n)overheadfromanactualpriorityqueue,byusingstacksandqueues

§  Canevencodeoneimplementa6onthattakesavariablequeuingobject

Page 105: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

SearchandModels

§  Searchoperatesovermodelsoftheworld§  Theagentdoesn’tactuallytryalltheplansoutintherealworld!

§  Planningisall“insimula6on”

§  Yoursearchisonlyasgoodasyourmodels…

Page 106: Graph Search · UCS vs BFS Remember: UCS explores increasing cost contours The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information

SearchGoneWrong?