This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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 depthfirst 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 = k1; End while; End;...
View
Full
Document
This document was uploaded on 09/03/2010.
 Fall '09

Click to edit the document details