Backtracking

Backtracking - Backtracking Examples: Maze problem The...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Backtracking Examples: Maze problem The bicycle lock problem: Consider a lock with N switches, each of which can be either 0 or 1. We know that the combination that opens the lock should have at least 2 N 1's. Note: The total number of combinations is 2 N The solution space can be modeled by a tree Finish Start Example: N=3 Characteristics Backtracking technique can be considered as an organized exhaustive search that often avoids searching all possibilities. The solution space can be organized as a tree called: search tree Use depth-first search technique The search tree is pruned using a bounding function. Assumptions: X[1..n] contains the solution of the problem All possible values of X[i]are elements of a set S i ROOT 1 000 001 010 011 101 110 111 100 00 01 10 11 General algorithm: Procedure backtrack(n) /* X is the solution vector */ Integer k; Begin k =1; Compute S k ; /* compute the possible solution values for k=1 */ While k> 0 do While S k <> do X[k] = an element of S k ; S k = S k-{X[k]}; If B(X[1], , X[i],, X[k]) = True Then Print the solution vector X; else begin k = k+1; Compute S k ; End; End; End while; k = k-1; End while; End;...
View Full Document

This document was uploaded on 09/03/2010.

Page1 / 13

Backtracking - Backtracking Examples: Maze problem The...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online