Algorithms

Spring 2013
course
navigation

Apr 4

backtracking

First, finish our discussion of backtrack search with the N-queens problem.
I have several related files in backtrack
The backtrack method is a brute-force (look at everything) incremental search. It works great ... as long as the search space isn't too big.
To work with any search problem, your first task is to find a way to represent the problem (typically as a list or matrix of numbers), and to write methods that manipulate that representation. Some typical tasks include

pruning

Discuss his sudoku example, and how/why he gets better results in backtrack by choosing to look next at the square with the fewest options.
What does a representation of this in python look like?
Aside:

heuristics

Very often the problem you're trying to solve is too big for brute-force, though, for example trying to solve N-queens for (say) a 30 x 30 board. (30! = 265252859812191058636308480000000)
So then what?
The general idea is to try to "look around" the search space and head in the right direction rather than just looking at everything.
There are a slew of variations on this theme. We'll just mention a couple now.
1. Random search.
2. local gradient search
3. Simulated annealing
4. genetic algorithm

more N-queens

In class: try to adapt the first few to the N-queens problem so that you see exactly what this looks like in practice.
For example: the heuristic can be the number of queens that can attack each other. (We want that to be 0, but if there are 30 queens on the board, having only 2 that can attack each other seems closer to a solution than if 28 can attack each other). Moving to a "nearby" position might mean moving one queen to a new column.

homework

Discuss the assignment, particularly what the representations, heuristic, and "neighbor" can mean for the traveling salesman problem.

next week

Coming next: game trees, min/max search, and alpha/beta pruning.
I have some related code in http://cs.marlboro.edu/courses/spring2013/algorithms/code/games/ , including the game_search.py that we looked at briefly in the intro programming course.
http://cs.marlboro.edu/ courses/ spring2013/algorithms/ notes/ Apr_4
last modified Thursday April 4 2013 2:51 am EDT