0% found this document useful (0 votes)
3 views

LU5 Exhaustive Search

The document discusses the concept of exhaustive search as a brute-force method for solving combinatorial problems, specifically focusing on the Traveling Salesman Problem (TSP) and the Knapsack Problem. It outlines the method of generating all potential solutions, evaluating them, and identifying the best solution, while also noting the efficiency of these approaches. Both TSP and Knapsack problems are identified as NP-hard, indicating the absence of known polynomial-time algorithms for their resolution.

Uploaded by

LekshmiRajesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

LU5 Exhaustive Search

The document discusses the concept of exhaustive search as a brute-force method for solving combinatorial problems, specifically focusing on the Traveling Salesman Problem (TSP) and the Knapsack Problem. It outlines the method of generating all potential solutions, evaluating them, and identifying the best solution, while also noting the efficiency of these approaches. Both TSP and Knapsack problems are identified as NP-hard, indicating the absence of known polynomial-time algorithms for their resolution.

Uploaded by

LekshmiRajesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

LU5-Exhaustive Search

Mrs. G. Priyanka, AP(Sl.Gr)/CSE


Mepco Schlenk Engineering College, Sivakasi

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

• evaluate potential solutions one by one, disqualifying


infeasible ones and, for an optimization problem, keeping
track of the best one found so far

• when search ends, announce the solution(s) found


Example 1: Traveling Salesman Problem

• Given n cities with known distances between each pair,


find the shortest tour that passes through all the cities
exactly once before returning to the starting city
• Alternatively: Find shortest Hamiltonian circuit in a
weighted connected graph
2
• Example: 1
a b
5
3 4
8

c 7 d
Example 1: Traveling Salesman Problem

How do we represent a solution (Hamiltonian circuit)?


• Hamiltonian circuit can also be defined as a sequence of
n + 1 adjacent vertices v0, v1, . . . , vn−1, v0,
where the first vertex of the sequence is the same as
the last one and all the other n − 1 vertices are distinct.

• Thus, we can get all the tours by generating all the


permutations of n − 1 intermediate cities, compute the
tour lengths, and find the shortest among them.
TSP by Exhaustive Search
Tour Cost
a→b→c→d→a 2+3+7+5 = 17
a→b→d→c→a 2+4+7+8 = 21
a→c→b→d→a 8+3+4+5 = 20
a→c→d→b→a 8+7+4+2 = 21
a→d→b→c→a 5+4+3+8 = 20
a→d→c→b→a 5+7+3+2 = 17

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)!)

• Improvement: The number of vertex


permutations can be cut by half.
• For example, choose any two intermediate
vertices, say, b and c, and then consider only
permutations in which b precedes c and thus
ignores c precedes b .

• Improved Efficiency: Θ((n-1)!)


Example 2: Knapsack Problem
• Problem: Given n items of known weights w1, w2, .
. . , wn and values v1, v2, . . . , vn and a knapsack
of capacity W, find the most valuable subset of the
items that fit into the knapsack.
Knapsack Problem by Exhaustive
Search
The exhaustive-search approach to this problem leads
to
• generating all the subsets of the set of n items
given
• computing the total weight of each subset in order
to identify feasible subsets (i.e., the ones with the
total weight not exceeding the knapsack capacity)
• finding a subset of the largest value among them

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

You might also like