Backtrackin
g
   William Fiset
  What is backtracking?
  Backtracking is a problem solving technique and
      general algorithm for solving computational
problems, especially constraint satisfaction problems.
   In practice, backtracking almost always involves
    using recursion and state pruning to explore a
                     solution space.
N-Queens Problem
    Problem Description:
Given an NxN grid find out how
many valid configurations exists
 where you can place N queens
without any queen being able to
       threaten another.
           Backtracking Ideas:
 Incrementally place queens on board
 Visit only valid partly completed states
 Position queens where not threatened
Depth First Search
               Problem Description:
         Find a path from the start to the end
                       of a maze.
       Backtracking Ideas:
 Plunge depth first into maze
 Backtrack when a dead end is encountered
 Do not revisit visited paths
Depth First Search
The same concept of backtracking can be used
  on a general graph to find a path from one
               node to another.
   S
       Solving Sudoku
      Problem Description:
 Sudoku puzzles are solved by filling
in the empty squares with numbers.
A valid puzzle must have the distinct
  numbers 1-9 in each row, column,
               and box.
               Backtracking Ideas:
          Too many possible boards to visit
          Visit only valid sudoku board states
          Prune invalid states
   Challenge       https://projecteuler.net/problem=96
       :
     Graph Coloring
                    "Graph coloring is coloring the
                   vertices of a graph such that no
                   two adjacent vertices share the
                             same color"
                              -Wikipedia
           Backtracking Ideas:
Start with uncolored graph
Assign a vertex a color if there is no conflict
Backtrack (undo) when graph is in invalid state
 River Crossing Problem
      Problem Description:
   The river crossing problem is
     a transportation problem
       where one must carry
    objects from one river bank
   to the other side under some
    constraints on the objects.
   Variations of the river crossing problem:
           Fox, goose and bag of beans puzzle
           Jealous husbands problem
           The bridge and the torch problem
Challenge open.kattis.com/problems/safepassage
    :
  Key Takeaways
Common theme of visiting only valid partially
 completed states and pruning illegal states.
     Backtracking is useful for constraint
  satisfaction or complete search problems.
    Backtracking algorithms are primarily
         implemented using recursion.
Key takeaways