LU5 Exhaustive Search
LU5 Exhaustive Search
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-1
Exhaustive Search
• Exhaustive search is simply a brute-force approach to
combinatorial problems.
• A brute force solution to a problem involving search for
an element with a special property, usually among
combinatorial objects such as permutations,
combinations, or subsets of a set.
Method:
• generate a list of all potential solutions to the problem in a
systematic manner
c 7 d
Example 1: Traveling Salesman Problem
Efficiency:
Θ((n-1)!)
• Improvement: 3 pairs of tour (same cost) that
differ only by directions so the total number of
permutations needed is still 1/2 *(n − 1)!
Example-2 – Find TSP starting with
city a
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-6
Example-2 – Find TSP starting with
city a (Contd.,)
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-7
TSP by Exhaustive Search
Efficiency:Θ((n-1)!)
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-10
Knapsack problem: Example
Example: Knapsack capacity
W=10
item weight value
1 7 $42
2 3 $12
3 4 $40
4 5 $25
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-11
Solution by exhaustive search
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-12
Example 2
Example: Knapsack capacity W=16
item weight value
1 2 $20
2 5 $30
3 10 $50
4 5 $10
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-13
Knapsack Problem by Exhaustive Search – Example
2 (Contd.,)
Subset Total weight Total value
{1} 2 $20
{2} 5 $30
{3} 10 $50
{4} 5 $10 Efficiency: Ω(2n)
{1,2} 7 $50
{1,3} 12 $70
{1,4} 7 $30 Since the number of subsets of an n-element set is
$80 2 , the exhaustive search leads to Ω(2 ) algorithm.
n n
{2,3} 15
{2,4} 10 $40
{3,4} 15 $60
{1,2,3} 17 TSP and Knapsack problems are NP-hard
not feasible
{1,2,4} 12 $60 problems. No polynomial-time algorithm is
{1,3,4} 17 known for any NP hard problem.
not feasible
{2,3,4} 20 not feasible
{1,2,3,4} 22 not feasible