Presentation is loading. Please wait.

Presentation is loading. Please wait.

Backtracking.

Similar presentations


Presentation on theme: "Backtracking."— Presentation transcript:

1 Backtracking

2 Basic Counting Principle
Suppose a set of tasks T = {t1, t2, …, tn} can be done in w1, w2,…, wn different ways, respectively. The sequence of tasks t1, t2, …, tn can be performed in W = w1 x w2 x…x wn many different ways. w1 1 2 w2 1 2 wn 1 2

3 Naive Backtracking A search or optimization algorithmic approach that is capable of exploring all configuration choices How does backtracking relate to exhaustive search? Example Problems: Constraint Satisfaction Nonthreatening queen placement Knights tour Optimization Knapsack TSP Work assignment

4 Sample Code class TTable { static int table[]; static int number;
public static void main(String args[]) { int N = 4;//The number of propositions number = N; table = new int[N+1]; tt(N); }//main static void tt(int N) { for (int i=1; i>-1; i--) if (N==1) { table[N] = i; for (int j = number; j>=1; j--) System.out.print(table[j]); System.out.println(" "); } else { tt(N-1); } //tt }//class

5 Branch and Bound An improvement to backtracking Optimization
Find a good solution quickly by some other means Keep a running record of the partial solution cost When the cost of the partial solution exceeds that of the best so far, Stop exploring that branch Back up to the next branch Any time a new solution is better than the best so far, replace the best so far with the new solution and use it for comparisons Could branch-and-bound be used for constraint satisfaction problems? If so, how? If not, why not?


Download ppt "Backtracking."

Similar presentations


Ads by Google