+ All Categories
Home > Documents > Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras...

Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras...

Date post: 17-Oct-2020
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
76
Problem Solving by Search Uwe Egly Vienna University of Technology Institute of Information Systems Knowledge-Based Systems Group
Transcript
Page 1: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Problem Solving by Search

Uwe Egly

Vienna University of TechnologyInstitute of Information Systems

Knowledge-Based Systems Group

Page 2: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Outline

Introduction

Search Problems

Search StrategiesBreadth-first SearchUniform-cost SearchDepth-first SearchDepth-limited SearchDepth-first Iterative Deepening Search

Tree vs Graph Search

Summary

Page 3: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Overview

Search: very important technique in CS and AI

Different kinds of search:

◮ Deterministic search◮ Uninformed (“blind”) search strategies◮ Informed or heuristic search strategies:

use information about problem structure

◮ Local search◮ Search in game trees (not covered in this course)

In this lecture: A quick recapitulation of deterministic search

Page 4: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Example for a Search Problem

What is the current situation?◮ On holiday in Romania; currently in Arad◮ Flight leaves tomorrow from Bucharest

What is the desired (or goal) situation?◮ To be in Bucharest in order to catch the flight

Formulate the problem!◮ Various cities◮ Drive between cities

Find a solution!◮ Sequence of cities from Arad to Bucharest

e.g., Arad, Sibiu, Fagaras, Bucharest

Page 5: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Example for a Search Problem: The Map

Giurgiu

UrziceniHirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

DobretaCraiova

Sibiu Fagaras

Pitesti

Vaslui

Iasi

Rimnicu Vilcea

Bucharest

71

75

118

111

70

75

120

151

140

99

80

97

101

211

138

146 85

90

98

142

92

87

86

Page 6: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

How do we Formulate a Search Problem?

A search problem consists of the following 4 components

1. An initial state or start state, e.g., be at Arad

2. A non-empty set of goal states, eitherimplicitly given as specific states, e.g., be at Bucharest, ordefined as all states satisfying the goal test

3. A non-empty set of operators (action-state pairs)

Zi Zi+1

costs

◮ E.g., drive from Arad to Sibiu◮ Transforms Zi into the successor state Zi+1◮ Associated to each operator are positive costs◮ No costs given unit costs

4. Function to compute the path costs from operator costse.g.,

∑of operator costs of operator applications on a path

Page 7: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Example of a Search Problem: 8-Puzzle

2

Start State Goal State

51 3

4 6

7 8

5

1

2

3

4

6

7

8

5

◮ States: integer locations of tiles (ignore intermediate positions)

◮ Operators: move blank left, right, up, down (ignore unjamming)

◮ Operator costs: unit cost, i.e., 1 per move

◮ Goal test: = goal state (given)

◮ Path costs: summation over operator costs on the path

◮ Solution: sequence of rules transforming start into a goal state

◮ State space dynamically generated by possible moves

Page 8: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

The State Space for the Holiday Example

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara

Arad Lugoj

Zerind

Arad Oradea

Find solution = search the state space for a path◮ from the start state◮ to a goal state

Page 9: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Search Strategies

A strategy is defined by picking the order of node expansion

Four important properties of a strategy:

1. Completeness: Does it always find a solution if one exists?

2. Space complexity: Maximum number of nodes in memory

3. Time complexity: Number of nodes generated/expanded

4. Optimality: Does it always find a least-cost solution?

Degree of complexity (poly, exp, etc.) always wrt problem size!

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 ∞)

Page 10: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Recall: Big O Notation

Definitiong(n) is in O(f (n)), if there exist two positive constants c and n0,such that

g(n) ≤ c · f (n)

holds for all n > n0.

Page 11: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uninformed Search Strategies (USS)

USSs use only the info available in the problem definition

◮ Breadth-first search◮ Uniform-cost search◮ Depth-first search◮ Depth-limited search◮ Iterative deepening search

Page 12: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Page 13: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Page 14: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu Timisoara Zerind

Page 15: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara Zerind

Page 16: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara

Arad Lugoj

Zerind

Page 17: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara

Arad Lugoj

Zerind

Arad Oradea

Page 18: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara

Arad Lugoj

Zerind

Arad Oradea

Page 19: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara

Arad Lugoj

Zerind

Arad Oradea

Page 20: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara

Arad Lugoj

Zerind

Arad Oradea

Page 21: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara

Arad Lugoj

Zerind

Arad Oradea

Page 22: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara

Arad Lugoj

Zerind

Arad Oradea

Page 23: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara

Arad Lugoj

Zerind

Arad Oradea

Page 24: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara

Arad Lugoj

Zerind

Arad Oradea

Page 25: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Breadth-first Search (BFS)

Idea: Expand a shallowest unexpanded node

Example: Search 3 levels to go from Arad to Bucharest

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara

Arad Lugoj

Zerind

Arad Oradea

Page 26: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Properties of BFS

Completeness: Yes (if b is finite)

Space complexity: O(bd), i.e., exponential in d(keep any node) (1 + b + b2 + . . . + bd = (bd+1

−1)(b−1) )

Time complexity: O(bd), i.e., exponential in d

Optimality: Yes (when using unit costs)

Page 27: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Page 28: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Page 29: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Timisoara118

118

Zerind75

75

Page 30: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Timisoara118

118

Zerind75

75

Arad

150

75

Oradea

146

71

Page 31: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Timisoara118

118

Arad

236

118

Lugoj

229

111

Zerind75

75

Arad

150

75

Oradea

146

71

Page 32: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Arad

280

140

Fagaras

239

99

Oradea

291

151

Rimnicu Vilcea

220

80

Timisoara118

118

Arad

236

118

Lugoj

229

111

Zerind75

75

Arad

150

75

Oradea

146

71

Page 33: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Arad

280

140

Fagaras

239

99

Oradea

291

151

Rimnicu Vilcea

220

80

Timisoara118

118

Arad

236

118

Lugoj

229

111

Zerind75

75

Arad

150

75

Oradea

146

71

Page 34: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Arad

280

140

Fagaras

239

99

Oradea

291

151

Rimnicu Vilcea

220

80

Timisoara118

118

Arad

236

118

Lugoj

229

111

Zerind75

75

Arad

150

75

Oradea

146

71

Page 35: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Arad

280

140

Fagaras

239

99

Oradea

291

151

Rimnicu Vilcea

220

80

Timisoara118

118

Arad

236

118

Lugoj

229

111

Zerind75

75

Arad

150

75

Oradea

146

71

Page 36: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Arad

280

140

Fagaras

239

99

Oradea

291

151

Rimnicu Vilcea

220

80

Timisoara118

118

Arad

236

118

Lugoj

229

111

Zerind75

75

Arad

150

75

Oradea

146

71

Page 37: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Arad

280

140

Fagaras

239

99

Oradea

291

151

Rimnicu Vilcea

220

80

Timisoara118

118

Arad

236

118

Lugoj

229

111

Zerind75

75

Arad

150

75

Oradea

146

71

Page 38: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Arad

280

140

Fagaras

239

99

Oradea

291

151

Rimnicu Vilcea

220

80

Timisoara118

118

Arad

236

118

Lugoj

229

111

Zerind75

75

Arad

150

75

Oradea

146

71

Page 39: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Arad

280

140

Fagaras

239

99

Oradea

291

151

Rimnicu Vilcea

220

80

Timisoara118

118

Arad

236

118

Lugoj

229

111

Zerind75

75

Arad

150

75

Oradea

146

71

Page 40: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Uniform-cost Search (UCS)

Idea: Expand an unexpanded node with minimal costs

Exa: Use∑

and search 3 levels to go from Arad to Bucharest

Arad

Sibiu140

140

Arad

280

140

Fagaras

239

99

Oradea

291

151

Rimnicu Vilcea

220

80

Timisoara118

118

Arad

236

118

Lugoj

229

111

Zerind75

75

Arad

150

75

Oradea

146

71

Page 41: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Properties of UCS

Special case: BFS (= UCS with unit costs)

Let C∗ be the costs of an optimal solution, ǫ positive

Completeness: Yes, if b is finite and operator cost ≥ ǫ

Space complexity: # of nodes with g ≤ C∗ is O(b⌈C∗/ǫ⌉)

Time complexity: # of nodes with g ≤ C∗ is O(b⌈C∗/ǫ⌉)

Optimality: Yes, because nodes expanded inincreasing order of g(n)

Attention: ⌈C∗/ǫ⌉ is an approximation for the depth

Page 42: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Arad

Arad

Page 43: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Sibiu

Arad

Sibiu Timisoara Zerind

Page 44: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Arad

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara Zerind

Page 45: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Arad

Arad

Sibiu

Arad Fagaras Oradea Rimnicu Vilcea

Timisoara Zerind

Page 46: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Fagaras

Arad

Sibiu

Fagaras Oradea Rimnicu Vilcea

Timisoara Zerind

Page 47: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Fagaras

Arad

Sibiu

Fagaras Oradea Rimnicu Vilcea

Timisoara Zerind

Page 48: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Oradea

Arad

Sibiu

Oradea Rimnicu Vilcea

Timisoara Zerind

Page 49: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Oradea

Arad

Sibiu

Oradea Rimnicu Vilcea

Timisoara Zerind

Page 50: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Rimnicu Vilcea

Arad

Sibiu

Rimnicu Vilcea

Timisoara Zerind

Page 51: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Rimnicu Vilcea

Arad

Sibiu

Rimnicu Vilcea

Timisoara Zerind

Page 52: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Sibiu

Arad

Sibiu Timisoara Zerind

Page 53: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Timisoara

Arad

Timisoara Zerind

Page 54: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Arad

Arad

Timisoara

Arad Lugoj

Zerind

Page 55: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Arad

Arad

Timisoara

Arad Lugoj

Zerind

Page 56: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Lugoj

Arad

Timisoara

Lugoj

Zerind

Page 57: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Lugoj

Arad

Timisoara

Lugoj

Zerind

Page 58: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Timisoara

Arad

Timisoara Zerind

Page 59: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Zerind

Arad

Zerind

Page 60: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Arad

Arad

Zerind

Arad Oradea

Page 61: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Arad

Arad

Zerind

Arad Oradea

Page 62: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Expand node Oradea

Arad

Zerind

Oradea

Page 63: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Oradea

Arad

Zerind

Oradea

Page 64: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Zerind

Arad

Zerind

Page 65: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Backtrack node Arad

Arad

Page 66: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Search (DFS)

Idea: Expand an unexpanded node of maximal depth

Example: Search the space given by BFS (i.e., fix it to 3 levels)

Search completed!

Page 67: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Properties of DFS

Problem: DFS can be non-terminating, i.e., m → ∞(even if a solution is in the search space)

Completeness: No

Space complexity: O(bm), i.e., space is linear in m!

Time complexity: O(bm) terrible if m is much larger than d

Optimality: No

Page 68: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-limited Search (DLS)

DLS: DFS with depth limit l (nodes at depth l have no successors)

Completeness: Yes, if l > d

Space complexity: O(bl)

Time complexity: O(bl)

Optimality: No

Page 69: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Iterative Deepening Search (DFIDS)

Idea: Set l = 0, 1, 2, . . . and use DLS with limit l as a subroutine

Limit = 0 A A

Page 70: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Iterative Deepening Search (DFIDS)

Idea: Set l = 0, 1, 2, . . . and use DLS with limit l as a subroutine

Limit = 1 A

B C

A

B C

A

B C

A

B C

Page 71: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Iterative Deepening Search (DFIDS)

Idea: Set l = 0, 1, 2, . . . and use DLS with limit l as a subroutine

Limit = 2 A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

Page 72: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Depth-first Iterative Deepening Search (DFIDS)

Idea: Set l = 0, 1, 2, . . . and use DLS with limit l as a subroutine

Limit = 3

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H J K L M N OI

A

B C

D E F G

H I J K L M N O

Page 73: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Properties of DFIDS

Completeness: Yes

Space complexity: O(bd)

Time complexity: O(bd)(d + 1)b0 + db1 + (d − 1)b2 + . . . + bd

Optimality: Yes (when using unit costs)

Page 74: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Tree Search vs Graph Search

◮ So far, the constructed search space was a tree◮ In travel example, paths like Arad–Sibiu–Arad occurred◮ Moreover, e.g., Arad occurred on several such paths◮ Expanding the same node more than once is

computationally expensive and should be avoided◮ Search is graph-based instead of tree-based

A

B

C

D

A

BB

CCCC

Page 75: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Benefits and Problems of Graph Search

◮ GS can be “exponentially more efficient” than tree search◮ With graph search, it is often harder to prove optimality◮ No problem for UCS with unit or constant step costs◮ In general: If > 1 paths to the same state exist, take care

that you choose the “good one” for the expansion◮ More problematic for heuristic search like A∗

(see next lecture)

Page 76: Problem Solving by Search · 2010. 10. 14. · Goal test: = goal state (given) ... 280 140 Fagaras 239 99 Oradea 291 151 Rimnicu Vilcea 220 80 Timisoara118 118 Arad 236 118 Lugoj

Summary

◮ Problem formulation usually requires abstracting awayreal-world details to define a state space that can feasiblybe explored

◮ Variety of uninformed search strategies◮ Iterative deepening search uses only linear space and not

much more time than other uninformed algorithms


Recommended