Top Banner

of 15

Backtracking and Band b

Apr 14, 2018

Download

Documents

Barga SP Deori
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 7/30/2019 Backtracking and Band b

    1/15

    Busby, Dodge, Fleming, and Negrusa

  • 7/30/2019 Backtracking and Band b

    2/15

    Backtracking Algorithm Is used to solve problems for which a sequence of

    objects is to be selected from a set such that thesequence satisfies some constraint

    Traverses the state space using a depth-first searchwith pruning

  • 7/30/2019 Backtracking and Band b

    3/15

    Backtracking Performs a depth-first traversal of a tree

    Continues until it reaches a node that is non-viable or

    non-promising Prunes the sub tree rooted at this node and continues

    the depth-first traversal of the tree

  • 7/30/2019 Backtracking and Band b

    4/15

    Example: N-Queens Problem Given an N x N sized chess board

    Objective: Place N queens on theboard so that no queens are in danger

  • 7/30/2019 Backtracking and Band b

    5/15

    One option would be to generate a tree of every

    possible board layout This would be an expensive way to find a solution

  • 7/30/2019 Backtracking and Band b

    6/15

    Backtracking Backtracking prunes entire

    sub trees if their root node isnot a viable solution

    The algorithm willbacktrack up the tree tosearch for other possiblesolutions

  • 7/30/2019 Backtracking and Band b

    7/15

    Efficiency of Backtracking This given a significant advantage over an exhaustive

    search of the tree for the average problem

    Worst case: Algorithm tries every path, traversing theentire search space as in an exhaustive search

  • 7/30/2019 Backtracking and Band b

    8/15

    Branch and BoundWhere backtracking uses a depth-first search with

    pruning, the branch and bound algorithm uses abreadth-first search with pruning

    Branch and bound uses a queue as an auxiliary datastructure

  • 7/30/2019 Backtracking and Band b

    9/15

    The Branch and Bound Algorithm Starting by considering the root node and applying a

    lower-bounding and upper-bounding procedure to it

    If the bounds match, then an optimal solution hasbeen found and the algorithm is finished

    If they do not match, then algorithm runs on the child

    nodes

  • 7/30/2019 Backtracking and Band b

    10/15

    Example:

    The Traveling Salesman Problem Branch and bound can be used to solve the TSP using

    a priority queue as an auxiliary data structure

    An example is the problem with a directed graphgiven by this adjacency matrix:

  • 7/30/2019 Backtracking and Band b

    11/15

    Traveling Salesman Problem The problem starts at vertex 1

    The initial bound for the minimum tour is the sum of

    the minimum outgoing edges from each vertex

    Vertex 1 min (14, 4, 10, 20) = 4

    Vertex 2 min (14, 7, 8, 7) = 7

    Vertex 3 min (4, 5, 7, 16) = 4

    Vertex 4 min (11, 7, 9, 2) = 2Vertex 5 min (18, 7, 17, 4) = 4

    Bound = 21

  • 7/30/2019 Backtracking and Band b

    12/15

    Traveling Salesman Problem Next, the bound for the node for the partial tour from 1

    to 2 is calculated using the formula:

    Bound = Length from 1 to 2 + sum of min outgoing edges

    for vertices 2 to 5 = 14 + (7 + 4 + 2 + 4) = 31

  • 7/30/2019 Backtracking and Band b

    13/15

    Traveling Salesman Problem The node is added to the priority queue

    The node with the lowest bound is then removed

    This calculation for the bound for the node of thepartial tours is repeated on this node

    The process ends when the priority queue is empty

  • 7/30/2019 Backtracking and Band b

    14/15

    Traveling Salesman Problem The final results of this

    example are in this tree:

    The accompanyingnumber for each node isthe order it was removedin

  • 7/30/2019 Backtracking and Band b

    15/15

    Efficiency of Branch and Bound In many types of problems, branch and bound is faster

    than branching, due to the use of a breadth-firstsearch instead of a depth-first search

    The worst case scenario is the same, as it will still visitevery node in the tree