breadth depth

Upload: pavitha-narayan

Post on 03-Jun-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Breadth Depth

    1/20

    State Space Search:

    Breadth First and Depth First

  • 8/12/2019 Breadth Depth

    2/20

    Motivations

    Many problems can be viewed as reaching agoal state from a given starting point, e.g., thefarmer-wolf-goat-cabbage problem.

    Often there is an underlying state space

    successor function to proceed from one stateto the next.

    Search strategies are important methods to

    explore such a space to obtain the goal state.

  • 8/12/2019 Breadth Depth

    3/20

    Objectives

    1. Top down search2. Bottom up search

    3. Breadth first search

    4. Depth first search5. Compare breadth first and depth first

  • 8/12/2019 Breadth Depth

    4/20

    State space for tic-tac-toe game

    Represent a problem

    as a state space

    Nodesrepresentdiscrete states, e.g.,

    configuration of game

    board.

    Arcs(links, edges)represent transition

    between states e.g.,

    move in a game.

    Analyze the structure

    and complexity ofproblem and search

    procedures using

    graph theory.

  • 8/12/2019 Breadth Depth

    5/20

    Am I a descendant of Thomas Jefferson?

    The third President of the United States (18011809)

    Assume no complete record of Jeffersons family tree. Need to do some research. 2 search strategies

    top-down: search from Jefferson to I

    bottom-up: search from I to Jefferson

    Assume 10 generations has past since Jefferson Depth of family tree is 10

    top-down Assume average 3 children per family

    branch factor is 3

    How many nodes to search?

    3 + 32 + 33+ + 310

    bottom-up For each child, search 2 parents

    branch factor is 2

    How many nodes to search?

    2 + 22 + 23+ + 210

  • 8/12/2019 Breadth Depth

    6/20

    Breadth-first searching

    A breadth-first search (BFS)explores nodes nearest the

    root before exploring nodes

    further away

    For example, aftersearching A, then B, then C,

    the search proceeds with D,

    E,F,G

    Node are explored in theorder A B C D E F G H I J K LM N O P Q

    Jwill be found beforeNL M N O P

    G

    Q

    H JI K

    FED

    B C

    A

  • 8/12/2019 Breadth Depth

    7/20

    Breadth-first search algorithm

    Nodes are lining up to be visited in open.

    closed keeps track of all the nodes visited already.

  • 8/12/2019 Breadth Depth

    8/20

    A trace of

    breadth-first algorithm

    || |

    ||| | |

    | | |

    ||||

    Items between redbars are siblings.

    B is not the goal.Put his children onto the queue.

    Put him in closed. He is done.

    goal is reached or open is empty.

  • 8/12/2019 Breadth Depth

    9/20

    || |

    ||| | |

    | | |

    ||||

    closed contains the nodes that

    have been visited, i.e., nodesthat have been opened or

    expanded.

    open contains the nodes

    whose children have not beenlooked at yet. The queue is

    also called the frontierof the

    search.

    Progress at iteration 6

  • 8/12/2019 Breadth Depth

    10/20

    Breadth-first searching summary

    L M N O P

    G

    Q

    H JI K

    FED

    B C

    A

  • 8/12/2019 Breadth Depth

    11/20

    Depth-first searching

    A depth-first search (DFS)explores a path all the way

    to a leaf beforebacktracking and exploring

    another path

    For example, after

    searching A, thenB, thenD, the search backtracksand tries another path from

    B

    Node are explored in theorder A B D E H L M N IO P C F G J K Q

    Nwill be found before JL M N O P

    G

    Q

    H JI K

    FED

    B C

    A

  • 8/12/2019 Breadth Depth

    12/20

    The depth-first search algorithm

    This is the only difference betweendepth-first and breadth-first.

  • 8/12/2019 Breadth Depth

    13/20

    A trace of

    depth-first algorithm

    top of stack

  • 8/12/2019 Breadth Depth

    14/20

    Snap shot at iteration 6frontier

    visited

  • 8/12/2019 Breadth Depth

    15/20

    Recursive depth-first search algorithm

    DFS(node v) {visit(v)for each child wof v, DFS(w)

    }

    Recursion uses a stack to store data for previous

    calls. The children nodes (ws)are placed on theundeclared (implicit) stack.

    Breadth first uses a queue instead of a stack, norecursion.

    At any given time, the top of the stack contains only

    the node on a path from the root to a goal. The stack only needs to be large enough to hold the

    deepest search path.

    When a goal node is found, the path can be extractedfrom the stack as the recursion unwinds.

  • 8/12/2019 Breadth Depth

    16/20

    Search sequences of depth-first and breadth-first

    Breadth first: A, B, C,

    Depth first: 1, 2, 3,

  • 8/12/2019 Breadth Depth

    17/20

    Comparing the ordering of search sequences

    Determine the order of nodes (states) to be examined

    Breadth-first search

    When a state is examined, all of its children are

    examined, one after another

    Explore the search space in a level-by-levelfashion

    Depth-first search

    When a state is examined, all of its children and

    their descendants are examined before any ofits siblings

    Go deeper into the search space where

    possible

  • 8/12/2019 Breadth Depth

    18/20

    Breadth-first search of the 8-puzzle

    Cannot moveblank downward

  • 8/12/2019 Breadth Depth

    19/20

    Depth-first search of 8-puzzle with a depth bound of 5

    Breadth-firsttook46 nodes.

  • 8/12/2019 Breadth Depth

    20/20

    Summary

    Graph representation Nodes are problem solution states Arcs are steps in problem solving

    State Space Search

    Find a solution path from start state to goalstate.

    Determine complexity of problem

    Many problems (TSP) have exponential

    complexity, impossible to search exhaustively

    Strategies to search large space need heuristic

    to reduce space and time complexity