• No results found

06 depth first breadth first

N/A
N/A
Protected

Academic year: 2020

Share "06 depth first breadth first"

Copied!
28
0
0

Loading.... (view fulltext now)

Full text

(1)

Depth First and Breadth First

Search

(2)

Definitions

Heuristics (Greek heuriskein = find, discover): "the study of the methods and rules of discovery and invention".

We use our knowledge of the problem to consider some

(not all) successors of the current state (preferably just one, as with an oracle). This means clipping the state space, gaining speed, but perhaps missing the solution!

In chess: consider one (apparently best) move, maybe a few -- but not all possible legal moves.

(3)

Definitions

(2)

For heuristic search to work, we must be able to rank the children of a node. A heuristic function takes a state and returns a numeric value -- a composite

assessment of this state. We then choose a child with the best score (this could be a maximum or

minimum).

A heuristic function can help gain or lose a lot, but finding the right function is not always easy.

The 8-puzzle: how many misplaced tiles? how many slots away from the correct place? and so on.

Water jugs: ???

(4)

Definitions

(3)

The principal gain -- often spectacular -- is the reduction of the state space. For example, the full tree for Tic-Tac-Toe has 9! leaves. If we consider symmetries, the tree becomes six times smaller, but it is still quite large.

With a fairly simple heuristic function we can get the tree down to 40 states. (More on this when we discuss games.)

Heuristics can also help speed up exhaustive,

(5)

Search strategies Evaluation

 A search strategy is defined by picking the order of node expansion

 Strategies are evaluated along the following dimensions:

 Completeness: does it always find a solution if one exists?  Optimality: does it always find a least-cost solution?

 Time Complexity: number of nodes generated

 Space Complexity: maximum number of nodes in memory

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

(6)

Search Strategies

Un-informed (Blind) Searches

We wonder in the search space without any idea

where the goal could be

Informed (Heuristic) Searches

Heuristic function guides us whether we are

getting near or far from the goal

Adversarial Searches

When two agents have conflicting goals, such as

(7)

Un-informed Search Strategies

Uninformed (Blind)

search strategies use only the

information available in the problem definition

 Breadth-first Search

 Depth-first search

 Uniform-cost search

 Depth-limited search

 Iterative deepening search

 Bi-directional Search

(8)

CS 103 8

Breadth-First Search

BFS follows the following rules:

1. Select an unvisited node x, visit it, have it be the

root in a BFS tree being formed. Its level is called the current level.

2. From each node z in the current level, in the

order in which the level nodes were visited, visit all the unvisited neighbors of z. The newly visited nodes from this level form a new level that

becomes the next current level.

3. Repeat step 2 until no more nodes can be visited.

4. If there are still unvisited nodes, repeat from Step

(9)

Breadth-first Search

 Expand shallowest node first, i.e., nodes visited 1st shall be

expanded 1st

 Implementation:

 Can be implemented by calling Tree-Search algo  use the fringe as a Queue, FIFO

 Put the newly expanded node at the back of the fringe  Fringe = A

(10)

10

Breadth-first Search

Check if A is goal, it is not, expand A,

remove A

(11)

Breadth-first Search

 Check if B is goal, it is not, expand B, remove B

 Fringe = C, D, E

 Check if C is goal, it is not, expand C, remove C

 Fringe = D, E, F, G

(12)

Breadth-first Search

Expand shallowest unexpanded node

 Check if D is goal, it is not, no children so remove D

 Fringe = E, F, G

 Search goes on until goal is found. Once it is found, the

search terminates

(13)

Properties of Breadth-first

S

earch

Complete:

Yes (if

b

is finite)

Optimal:

Yes (if cost = 1 per step)

Time:

1+b+b

2

+b

3

+… +

b

d

+ (

b

d+1

-b

) =

O(b

d+1

)

Space:

O(b

d+1

)

(keeps every node in memory)

 Memory requirements are the bigger are bigger problem

 Exponential-complexity problems cannot be solved by

un-informed searche

(14)

Depth Nodes Time Memory

2 1,100 .11 Secs 1 MB

4 111,100 11 Secs 106 MB

6 107 19 Mins 10 GB

8 109 31 Hrs 1 TB

10 1011 120 Days 101 TB

12 1013 35 Years 10 PB

14 1015 3,523 Years 1 XB

14

Breadth-first Search

(15)

CS 103 15

Depth-First Search

DFS follows the following rules:

1. Select an unvisited node x, visit it, and treat as

the current node

2. Find an unvisited neighbor of the current node,

visit it, and make it the new current node;

3. If the current node has no unvisited neighbors,

backtrack to the its parent, and make that parent the new current node;

4. Repeat steps 3 and 4 until no more nodes can be

visited.

5. If there are still unvisited nodes, repeat from

(16)

Depth-first Search

Expand deepest unexpanded node

 Goes to the deepest level of the search tree where there are no further successors

 Implementation:

 use fringe as a Stack, LIFO

 Put the expanded node at the front of the fringe  Fringe = A

(17)

Depth-first Search

 Expand deepest unexpanded node

 Check if A is goal, it is not, expand A, remove A

 Fringe = B,C

(18)

Depth-first Search

Check if B is goal, it is not, expand B, remove B

Fringe = D,E,C

(19)

Depth-first Search

Check if D is goal, it is not, expand D, remove D

Fringe = H, I, E, C

(20)

Depth-first Search

 Both H and I has not successors so remove them if it is not

goal

Fringe = E, C

(21)

Depth-first Search

Che

ck

if E

is goal, it is not, expand E, remove E

 Fringe = J, K, C

(22)

Depth-first Search

J and K do not have successors neither is

any of them goal so remove them from

fringe one by one

 Fringe = C

(23)

Depth-first Search

Check if C is goal, it is not, expand C, remove C

 Fringe = F, G

(24)

Depth-first Search

Check if F is goal, it is not, expand F, remove F

Fringe = L, M, G

(25)

Depth-first Search

 Both L, M are not goal, neither they have any successor

 Remove L, M from fringe

 Fringe = G

 Check if G is goal, it is

 The search terminates

(26)

Properties of Depth-first

S

earch

 Complete? No: fails in infinite-depth spaces, spaces with

loops

 Complete in finite state space

 Modify to avoid repeated states along path

Optimal?

No

 Time? O(bm): terrible if m is much larger than d  Space? O(bm), i.e., linear space

(27)

Expands a node with the lowest path cost

May get stuck in infinite loop if a node has a

zero-cost action leading back to the same

state

Equivalent to breadth-first if all step costs

are equal

Implementation

:

fringe

= queue ordered by path cost

27

(28)

Uniform-cost Search

 The search is guided by the path cost instead of depths, so

complexity cannot be easily characterized by b and d

 Let C * is the cost of the optimal solution and every action

cost is at least ε

 Complete? Yes, if step cost ≥ ε, a positive number

 Optimal? Yes – nodes expanded in increasing order of g(n)

 Time? # of nodes with g ≤ cost of optimal solution,

O(b[C*/ ε])

 Space? # of nodes with g ≤ cost of optimal solution,

O(b[C*/ ε])

References

Related documents

misuse of information – whether consumer or company – and should allow for the testing and verification of new products in the market to ensure its quality standards reach up to the

T-bet, a transcription factor associated with T cell ef- fector function, was elevated in response to all of the Figure 1 Influence of γ c cytokines on proliferation, survival

 Increases the funding for the Co-op & Internship Program, 235-649, to $8 million per year (and increase of $6 million in FY’15) and earmarks $75,000 per year to each of

This research takes advantage of the World Bank Knowledge Assessment Methodology (KAM) framework to measure the sub-index of innovation and Triple-Helix model to

It is important to note that in many cases the major or cognate requirements for The secondary education minor is designed for students who in- tend to qualify for a teacher

This dissertation considers three questions related to the theory and application of semiparametric methods: the optimal bandwidth selection of CDF estimation of mixed

OY1110 LoRaWAN Temperature and humidity sensor, User manual, Version 1.0 14 Size: 1 Byte (Grouping header) + n x 3 Byte (Measurement value) where n = number of grouped

This document updates and supersedes the previously retained section 6 of RDA 4. This document has been renamed “Guideline Distances from Development to Trees - Securing Space