Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are...

12
Design and Analysis of Algorithms - Chapter 11 1 How to tackle those How to tackle those difficult problems... difficult problems... There are two principal approaches to There are two principal approaches to tackling NP-hard problems or other tackling NP-hard problems or other “intractable” problems: “intractable” problems: Use a strategy that guarantees solving the Use a strategy that guarantees solving the problem exactly but doesn’t guarantee to problem exactly but doesn’t guarantee to find a solution in polynomial time find a solution in polynomial time Use an approximation algorithm that can Use an approximation algorithm that can find an approximate (sub-optimal) solution find an approximate (sub-optimal) solution in polynomial time in polynomial time

Transcript of Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are...

Page 1: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 1

How to tackle those difficult How to tackle those difficult problems...problems...

There are two principal approaches to tackling NP-hard There are two principal approaches to tackling NP-hard problems or other “intractable” problems:problems or other “intractable” problems:

Use a strategy that guarantees solving the problem exactly Use a strategy that guarantees solving the problem exactly but doesn’t guarantee to find a solution in polynomial timebut doesn’t guarantee to find a solution in polynomial time

Use an approximation algorithm that can find an Use an approximation algorithm that can find an approximate (sub-optimal) solution in polynomial timeapproximate (sub-optimal) solution in polynomial time

Page 2: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 2

Exact solutionsExact solutions

The exact solution approach includes the strategies:The exact solution approach includes the strategies: exhaustive searchexhaustive search (brute force) (brute force)

• useful only for small instancesuseful only for small instances

backtrackingbacktracking• eliminates some cases from considerationeliminates some cases from consideration

branch-and-boundbranch-and-bound• further cuts down on the searchfurther cuts down on the search

• fast solutions for most instances fast solutions for most instances

• worst case is still exponentialworst case is still exponential

Page 3: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 3

BacktrackingBacktracking

Construct the Construct the state space treestate space tree::• nodes: partial solutionsnodes: partial solutions

• edges: choices in completing solutionsedges: choices in completing solutions

Explore the state space tree using depth-first searchExplore the state space tree using depth-first search

““Prune” non-promising nodesPrune” non-promising nodes• dfs stops exploring subtree rooted at nodes leading to no solutions dfs stops exploring subtree rooted at nodes leading to no solutions

and...and...

• ““backtracks” to its parent nodebacktracks” to its parent node

Page 4: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 4

Example: The Example: The nn-Queen -Queen problemproblem

Place Place n n queens on an queens on an nn by by nn chess board so that no chess board so that no two of them are on the same row, column, or two of them are on the same row, column, or diagonaldiagonal

Page 5: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 5

State-space of the four-queens State-space of the four-queens problemproblem

Page 6: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 6

Example: The Example: The mm-coloring -coloring problemproblem

Given a graph and an integer Given a graph and an integer mm, color its vertices using no , color its vertices using no more than more than mm colors so that no two adjacent vertices are the colors so that no two adjacent vertices are the same color.same color.

c d

a

eb

Page 7: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 7

Branch and BoundBranch and Bound

An enhancement of backtrackingAn enhancement of backtracking Applicable to optimization problemsApplicable to optimization problems Uses a lower bound for the value of the objective function Uses a lower bound for the value of the objective function

for each node (partial solution) so as to:for each node (partial solution) so as to:• guide the search through state-spaceguide the search through state-space

• rule out certain branches as “unpromising”rule out certain branches as “unpromising”8

17 10 8

14 1113122017

Page 8: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 8

Select one element in each row of the cost matrix Select one element in each row of the cost matrix CC so that: so that: • no two selected elements are in the same column; and no two selected elements are in the same column; and • the sum is minimizedthe sum is minimizedFor example:For example:

Job 1 Job 2 Job 3 Job 4Person a 9 2 7 8Person b 6 4 3 7Person c 5 8 1 8Person d 7 6 9 4

Lower boundLower bound: Any solution to this problem will have : Any solution to this problem will have total cost of total cost of at leastat least: :

Example: The assignment Example: The assignment problemproblem

Page 9: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 9

Assignment problem: lower Assignment problem: lower boundsbounds

Page 10: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 10

State-space levels 0, 1, 2State-space levels 0, 1, 2

Page 11: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 11

Complete state-spaceComplete state-space

Page 12: Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.

Design and Analysis of Algorithms - Chapter 11 12

Traveling salesman example:Traveling salesman example: