williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/williams_2.pdf · brian...

35
Brian Williams, Spring 03 1 Analysis of Uninformed Search Methods Brian C. Williams 16.410 Feb 18 th , 2003 Slides adapted from: 6.034 Tomas Lozano Perez, Russell and Norvig AIMA

Upload: others

Post on 22-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 1

Analysis of Uninformed Search Methods

Brian C. Williams16.410 Feb 18th, 2003Slides adapted from:

6.034 Tomas Lozano Perez,Russell and Norvig AIMA

Page 2: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 2

Assignment

• Reading: – Solving problems by searching: AIMA Ch. 3– Informed search and exploration: AIMA Ch. 4.1-2

• Homework:– Online problem set 2 due next Monday Feb 24th

Page 3: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 3

Outline

• Recap• Analysis

– Depth-first search– Breadth-first search

• Iterative deepening

Page 4: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 4

Complex missions must carefully:

• Plan complex sequences of actions

• Schedule tight resources

• Monitor and diagnose behavior

• Repair or reconfigure hardware.

ðMost AI problems, like these, may be formulated as state space search.

Page 5: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 5

AstronautGooseGrain

Fox

GrainFox

AstronautGoose

AstronautGrain

Fox

Goose

Goose

AstronautFox

Grain

AstronautGoose

GrainFox

AstronautGooseGrainFox

Grain

AstronautGoose

Fox

AstronautGooseGrain

Fox

Fox

AstronautGooseGrain

AstronautGoose

Fox

Grain

GooseFox

AstronautGrain

GooseGrain

AstronautFox

AstronautGrain

GooseFox

AstronautFox

GooseGrain

GooseGrainFox

Astronaut

Astronaut

GooseGrain

Fox

• Formulate Goal• Formulate Problem

– States– Operators

• Generate Solution– Sequence of states

Problem Solving Searches Paths in a Graph

Page 6: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 6

Depth First Search (DFS)S

D

BA

C G

C G

D

C G

S

D

BA

C G

C G

D

C G

Breadth First Search (BFS)

Depth-first:

Add path extensions to front of Q

Pick first element of Q

Breadth-first:

Add path extensions to back of Q

Pick first element of Q

Page 7: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 7

Simple Search AlgorithmLet Q be a list of partial paths, Let S be the start node and Let G be the Goal node.

1. Initialize Q with partial path (S) as only entry; set Visited = ( )

2. If Q is empty, fail. Else, pick some partial path N from Q

3. If head(N) = G, return N (goal reached!)

4. Else

a) Remove N from Q

b) Find all children of head(N) not in Visited and create all the one-step extensions of N to each child.

c) Add to Q all the extended paths;

d) Add children of head(N) to Visited

e) Go to step 2.

Page 8: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 8

Outline

• Recap• Analysis

– Depth-first search– Breadth-first search

• Iterative deepening

Page 9: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 9

Elements of Algorithmic Analysis

• Soundness: – is a solution returned by the algorithm guaranteed to be correct?

• Completeness: – is the algorithm guaranteed to find a solution when there is one?

• Optimality:– is the algorithm guaranteed to find a best solution when there is one?

• Time complexity: – how long does it take to find a solution?

• Space complexity: – how much memory does it need to perform search?

Page 10: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 10

Characterizing Search Algorithms

d = 1

Level 1

Level 2

Level 0b = 3

b = maximum branching factor, number of childrend = depth of the shallowest goal nodem = maximum length of any path in the state space

m = 1

Page 11: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 11

Cost and Performance

Breadth-first

Depth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

Which is better, depth-first or breadth-first?

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

S

D

BA

C G

C G

D

C G

C

S

B

GA

D

Page 12: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 12

Worst Case Time for Depth-firstWorst case time T is proportional to number of nodes visited

Tdfs = bm + … b + 1b * Tdfs = bm+1 + bm + … b Solve recurrence

[b – 1] * Tdfs = bm+1 – 1

Tdfs = [bm+1 – 1]/[b – 1] *cdfs where cdfs is time per node

Level 1

Level 2

Level 0

b*1

b*b

b*bm-1

. . .Level m

1

Page 13: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 13

Cost Using Order NotationWorst case time T is proportional to number of nodes visited

Level 1

Level 2

Level 0

b*1

b*b

b*bm-1

. . .

Order Notation• T = O(e) if T = c * e for some constant c

Tdfs = [bm + … b + 1]*cdfs

= O(bm) for large b= O(bm+1) more conservatively

1

Page 14: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 14

Cost and Performance

Breadth-first

bmDepth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

Which is better, depth-first or breadth-first?

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

S

D

BA

C G

C G

D

C G

C

S

B

GA

D

Page 15: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 15

Worst Case Space for Depth-firstWorst case space Sdfs is proportional to maximal length of Q

• If a node is queued its parent and parent’s siblings have been queued. è Sdfs = (b-1)*m+1

The children of at most one sibling is expanded at each level. è Sdfs = (b-1)*m+1

• Sdfs = O(b*m)

Level 1

Level m

Level 0

b-1

b-1

b. . .

Page 16: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 16

Cost and Performance

Breadth-first

b*mbmDepth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

Which is better, depth-first or breadth-first?

S

D

BA

C G

C G

D

C G

C

S

B

GA

D

Page 17: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 17

Cost and Performance

Breadth-first

Nob*mbmDepth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

Which is better, depth-first or breadth-first?

S

D

BA

C G

C G

D

C G

C

S

B

GA

D

Page 18: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 18

Cost and Performance

Breadth-first

Yes for finite graphNob*mbmDepth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

Which is better, depth-first or breadth-first?

S

D

BA

C G

C G

D

C G

C

S

B

GA

D

Page 19: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 19

Cost and Performance

Breadth-first

Yes for finite graphNob*mbmDepth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

S

D

BA

C G

C G

D

C G

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

Which is better, depth-first or breadth-first?

C

S

B

GA

D

Page 20: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 20

Worst Case Time for Breadth-firstWorst case time T is proportional to number of nodes visited

Level 1

Level d

Level 0

Tbfs = [bd+1 + bd + … b + 1 - b]*cbfs

= O(bd+1)

Level d+1

b

bd+1- b

. . .

1

bd

Page 21: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 21

Cost and Performance

bd+1Breadth-first

Yes for finite graphNob*mbmDepth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

S

D

BA

C G

C G

D

C G

Which is better, depth-first or breadth-first?

C

S

B

GA

D

Page 22: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 22

Worst Case Space for Breadth-first

Level 1

Level d

Level 0

Sbfs = [bd+1- b + 1]*cbfs

= O(bd+1)

Level d+1

b

bd+1- b

. . .

1

bd

Worst case space Sdfs is proportional to maximal length of Q

Page 23: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 23

Cost and Performance

bd+1bd+1Breadth-first

Yes for finite graphNob*mbmDepth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

S

D

BA

C G

C G

D

C G

Which is better, depth-first or breadth-first?

C

S

B

GA

D

Page 24: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 24

Breadth-first Finds Shortest Path

G

Level 1

Level d

Level 0

GLevel d+1

Firstreached

Nodes visited earlier can’t include G

Assuming each edge is length 1, other paths to G must be at least as long as first found

Page 25: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 25

Cost and Performance

Yes unit lngthbd+1bd+1Breadth-first

Yes for finite graphNob*mbmDepth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

S

D

BA

C G

C G

D

C G

Which is better, depth-first or breadth-first?

C

S

B

GA

D

Page 26: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 26

Cost and Performance

YesYes unit lngthbd+1bd+1Breadth-first

Yes for finite graphNob*mBmDepth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

S

D

BA

C G

C G

D

C G

Which is better, depth-first or breadth-first?

C

S

B

GA

D

Page 27: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 27

Growth for Best First Searchb = 10; 10,000 nodes/sec; 1000 bytes/node

1 exabyte3,523 years101514

10 petabytes35 years101312

101 terabytes129 days101110

1 terabyte31 hours1098

10 gigabytes19 minutes1076

106 megabytes11 seconds111,1004

1 megabyte.11 seconds1,1002

MemoryTimeNodesDepth

Page 28: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 28

Cost and Performance

YesYes unit lngthbd+1bd+1Breadth-first

Yes for finite graphNob*mbmDepth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

S

D

BA

C G

C G

D

C G

Which is better, depth-first or breadth-first?

C

S

B

GA

D

Page 29: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 29

Cost and Performance 6.034 Style: What the Electronic Tutor Thinks

YesYes unit lngthbdbd+1Breadth-first

Yes for finite graphNob*dbd+1Depth-first

Guaranteed tofind path?

ShortestPath?

WorstSpace

WorstTime

SearchMethod

Worst case time is proportional to number of nodes visitedWorst case space is proportional to maximal length of Q

S

D

BA

C G

C G

D

C G

Which is better, depth-first or breadth-first?

C

S

B

GA

D

• Assumes d = m in the worst case, and calls both d.

• Takes the conservative estimate: bd + … 1 = O(bd+1)

Page 30: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 30

Outline

• Recap• Analysis• Iterative deepening

Page 31: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 31

Iterative Deepening (IDS)

S

D

BA

C G

C G

D

C G

Level 1

Level 2

Level 0

Level 3

Idea: • Explore tree in breadth-first order, using depth-first search.è Search tree to depth 1, ….

Page 32: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 32

Iterative Deepening (IDS)

S

D

BA

C G

C G

D

C G

Level 1

Level 2

Level 0

Level 3

Idea: • Explore tree in breadth-first order, using depth-first search.è Search tree to depth 1, then 2, ….

Page 33: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 33

Iterative Deepening (IDS)

S

D

BA

C G

C G

D

C G

Idea: • Explore tree in breadth-first order, using depth-first search.è Search tree to depth 1, then 2, then 3….

Level 1

Level 2

Level 0

Level 3

Page 34: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 34

Cost of Iterative Deepening

• Tids = d + 1 + (d)b + (d - 1)b2 +. . . bd = O(bd) • Tbfs = 1+b + b2 + . . . bd + (bd+1 – b) = O(bd+1)èIterative deepening performs better than breadth-first!

S

D

BA

C G

C G

D

C G

d*b

1*bd

. . .

d+1

2*bd-1

Level 1

Level 2

Level 0

Level d

Page 35: williams.l4 analysis uninformed searchweb.mit.edu/16.070/www/lecture/Williams_2.pdf · Brian Williams, Spring 03 4 Complex missions must carefully: • Plan complex sequences of actions

Brian Williams, Spring 03 35

Summary• Most problem solving tasks may be encoded as state space

search.• Basic data structures for search are graphs and search trees.• Depth-first and breadth-first search may be framed,

among others, as instances of a generic search strategy.• Cycle detection is required to achieve efficiency and

completeness.• Complexity analysis shows that breadth-first is preferred in

terms of optimality and time, while depth-first is preferred in terms of space.

• Iterative deepening draws the best from depth-first and breadth-first search.