Review more backtracking examples Graph Coloring State space
Review: more backtracking examples Graph Coloring State space vector: {C 1, C 2, C 3, . . . Cn = #vertices } Choices: up to n possible colors for each vertex Pruning: • only try 1 color for V 1, 1 for V 2 if adjacent, . . . • choose vertices adjacent to previous vertices • start at vertex of highest degree Hamiltonian Circuit State space vector: {C 1, C 2, C 3, . . . Cn = #vertices } Choices: any unvisited vertex adjacent to the preceding choice Pruning: • only try 1 starting vertex • start at vertex of lowest degree • test for reachability of remaining vertices ____________________________ Question: Which problem is harder?
Backtracking examples: N-Queens Can you place N Queens? Subset Sum How close can you get to the limit? Graph Coloring Minimum colors needed? Hamiltonian Circuit Can you find tour that visits everything? Characteristics: • possibly many solutions • single main constraint Optimization Problems: 0/1 Knapsack Traveling Sales Person Fill bag? & Largest Value? Hamiltonian Circuit? & Shortest Length? Characteristics: • possibly many solutions • multiple constraints • can numerically rank solution
A B C D weight $/lb 11 12 30 10 20 9 10 8 total value 132 300 180 80 E F G H weight $/lb 19 5 6 5 3 4 7 4 total value odd years 95 30 12 28
odd years
odd years
- Slides: 6