From charlesreid1

(Created page with "The idea behind backtracking is to use recursion to explore a problem. The recursive backtracking method follows a common generic template: <pre> explore(choices): if(no...")
 
No edit summary
Line 20: Line 20:


Let's examine the 8 queens problem to see backtracking in action.
Let's examine the 8 queens problem to see backtracking in action.
[[Category:Computer Science]]

Revision as of 21:34, 12 March 2017

The idea behind backtracking is to use recursion to explore a problem.

The recursive backtracking method follows a common generic template:

explore(choices):
    if(no choices left):
        check if this is a solution
        if this is a solution:
            save it
    else:
        make a choice
        explore(remaining choices)
        unmake choice

Examples

8 Queens Problem

Let's examine the 8 queens problem to see backtracking in action.