• Nie Znaleziono Wyników

Depth-first Search

N/A
N/A
Protected

Academic year: 2021

Share "Depth-first Search"

Copied!
7
0
0

Pełen tekst

(1)

Depth-first Search

Depth-first search treats the frontier as a stack

It always selects one of the last elements added to the frontier.

If the frontier is [p1, p2, . . .]

p1 is selected. Paths that extend p1 are added to the front of the stack (in front of p2.

p2 is only selected when all paths from p1 have been explored.

(2)

2

3

4

5 7

12

13

14

15 16

(3)

Complexity of Depth-first Search

Depth-first search isn’t guaranteed to halt on infinite graphs or on graphs with cycles.

The space complexity is linear in the size of the path being explored.

Search is unconstrained by the goal until it happens to stumble on the goal.

(4)

Breadth-first search treats the frontier as a queue.

It always selects one of the earliest elements added to the frontier.

If the frontier is [p1, p2, . . . , pr]:

p1 is selected. Its neighbors are added to the end of the queue, after pr.

(5)

Illustrative Graph — Breadth-first Search

1

2 3

4 5 6 7

8 9 10 11 12 13 14

15 16

(6)

The branching factor of a node is the number of its neighbors.

If the branching factor for all nodes is finite, breadth-first search is guaranteed to find a solution if one exists.

It is guaranteed to find the path with fewest arcs.

Time complexity is exponential in the path length:

bn, where b is branching factor, n is path length.

(7)

Lowest-cost-first Search

Sometimes there are costs associated with arcs. The cost of a path is the sum of the costs of its arcs.

cost(n0, . . . , nk) =

k

i=1

|ni−1, ni|

At each stage, lowest-cost-first search selects a path on the frontier with lowest cost.

The frontier is a priority queue ordered by path cost.

It finds a least-cost path to a goal node.

When arc costs are equal ⇒ breadth-first search.

Cytaty

Powiązane dokumenty

It is proved that a doubly stochastic operator P is weakly asymptotically cyclic if it almost overlaps supports1. If moreover P is Frobenius–Perron or Harris then it is

Since the identity (x + y)y = y in Theorem 1.1 is nonregular we see that according to the last lemma we consider in the sequel bi-near-semilattices with one absorption

Berndtsson-Lempert Proof 2 can be improved to obtain the Ohsawa- Takegoshi extension theorem with optimal constant (one has to use Berndtsson’s positivity of direct

Using similar methods one can obtain a slightly more general result, the extension theorem with negligible weight and optimal

(a) Write the following statements in symbolic logic form (i) “If the sun is shining then I will walk to school.”.. (ii) “If I do not walk to school then the sun is

(b) Find the Cartesian equation of the plane Π that contains the two lines.. The line L passes through the midpoint

(b) Find the probability that a randomly selected student from this class is studying both Biology and

• Suppose that a population grows according to a logistic model with carrying capacity 6,000 and k = 0.0015 per year.. Write the logistic differential equation for