{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Backtracking

# Backtracking - Backtracking Examples Maze problem Finish...

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

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

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

View Full Document
ü 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 0 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;

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 13

Backtracking - Backtracking Examples Maze problem Finish...

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

View Full Document
Ask a homework question - tutors are online