You are on page 1of 13

Lecture-10

Exhaustive Search-2

Copyright © 2007 Pearson Addison-Wesley. All rights reserved.


Exhaustive Search-Examples

Travelling Salesman Problem (TSP) : Given a set of cities


and distances between every pair of cities, the problem is
to find the shortest possible route that visits every city
exactly once and returns to the starting point.

Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-1
Example 1: Traveling Salesman Problem

minimum weight Hamiltonian Cycle : 10 + 25 + 30 + 15 := 80


How do we represent a solution (Hamiltonian circuit)?
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-2
TSP by Exhaustive Search

For example, consider the graph shown in the figure on


the right side. A TSP tour in the graph is 1-2-4-3-1. The
cost of the tour is 10+25+30+15 which is 80.
The problem is a famous NP-hard problem. There is no
polynomial-time known solution for this problem.

Θ((n-1)!)

Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-3
TSP-Examples

Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-4
TSP examples

Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-5
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-6
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-7
Example 2: Knapsack Problem
Given n items:
• weights: w1 w2 … wn
• values: v1 v2 … vn
• a knapsack of capacity W
Find most valuable subset of the items that fit into the knapsack

Example: Knapsack capacity W=10


item weight value
1 3 $20
2 4 $30
3 9 $90
4 5 $10
5 2 $15
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-8
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-9
Example 2: Knapsack Problem

Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-10
Example 3: The Assignment Problem

Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-11
Final Comments on Exhaustive Search

Exhaustive-search
algorithms run in a
realistic amount of time
only on very small
instances

• Euler circuits
In some cases, there are • shortest paths
much better alternatives! • minimum spanning tree
• assignment problem

In many cases, exhaustive


search or its variation is
the only known way to
get exact solution

Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 3 3-12

You might also like