Top Banner
CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some by Iker Gondra
21

CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Dec 15, 2015

Download

Documents

Delilah Gulsby
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

CSCI 256

Data Structures and Algorithm Analysis

Lecture 22

Some slides by Kevin Wayne copyright 2005,

Pearson Addison Wesley all rights reserved,

and some by Iker Gondra

Page 2: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Transition point

• Till now we’ve looked at developing efficient algorithms for a wide range of problems

• Now we look to quantify or characterize the range of problems that can’t be solved efficiently

• We’ll use the notion of reduction to help compare the relative difficulty of different problems

Page 3: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

The Universe

NP-Complete

NP

P

Millennium Prize Problems

Copyright © 1990, Matt Groening

Page 4: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Classify Problems According to Computational Requirements

• Q: Which problems will we be able to solve in practice?– A working definition. [Cobham 1964, Edmonds 1965, Rabin

1966] Those with polynomial-time algorithms

• Desiderata: Classify problems according to those that can be solved in polynomial-time and those that cannot

• Frustrating news: Huge number of fundamental problems have defied classification for decades – i.e. can’t give a poly time alg and can’t prove that none exists

• This chapter: Show that these fundamental problems are "computationally equivalent" and appear to be different manifestations of one really hard problem

Page 5: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Polynomial-Time Reduction

• Desiderata': Suppose we could solve Y in polynomial-time. What else could we solve in polynomial time?

• Reduction: Problem X polynomial reduces to problem Y if arbitrary instances of problem X can be solved using– Polynomial number of standard computational steps,

plus– Polynomial number of calls to an oracle (a black box)

that solves problem Y

• Notation: X P Ycomputational model supplemented by special pieceof hardware that solves instances of Y in a single step

Page 6: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Lemma

• Suppose X P Y. If Y can be solved in polynomial time, then X can be solved in polynomial time

• Remark – when you are reading the text note that the text talks of Y P X

Page 7: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Lemma

• Suppose X P Y. If X cannot be solved in polynomial time, then Y cannot be solved in polynomial time

Page 8: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Polynomial-Time Reduction

• Purpose: Classify problems according to relative difficulty

• Design algorithms: If X P Y and Y can be solved in polynomial-time, then X can also be solved in polynomial time

• Establish intractability: If X P Y and X cannot be solved in polynomial-time, then Y cannot be solved in polynomial time

• Establish equivalence: If X P Y and Y P X, we use notation X P Yup to cost of reduction

Page 9: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Independent Set

• Independent Set– Goal is to find S of maximum size

1

3

2

6 7

4 5

Page 10: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Decision Problem

• Call the above an optimization version of the problem

• There is another way to formulate the problem – as a decision problem

• A decision problem is a class of problems for which there is a yes or no answer for each instance of the problem.

• We rephrase the Independent Set problem as the following decision problem

Page 11: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Independent Set – Decision version

- Given a graph G = (V, E) and an integer k, does G contain an independent set of size at least k?

– Ex: Instance: For G below, is there an independent set of size 6? Yes

– Ex: Instance: For G below, is there an independent set of size 7? No

independent set

Sample Application: find set of mutually

non-conflicting points

Page 12: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Equivalence between decision and optimization versions

• Given a method to solve the optimization version, we automatically solve each instance of the associated decision problem; and if we have a method to solve each instance of the decision then we can solve the optimization version (for given G, the the largest k for which there is a yes answer gives us the answer to the optimization version for G)

Page 13: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Vertex Cover

• Vertex Cover– Given a graph G = (V, E), a subset S of the vertices is

a vertex cover if every edge in E has at least one endpoint in S. Goal is to find S of minimum size

1

3

2

6 7

4 5

Page 14: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Vertex Cover – Associated decision version – if you can do optimization version you can do decision version and vice versa

• Convert to decision version of the problem– Given a graph G = (V, E) and an integer k, does G contain a

vertex cover of size at most k?

– Ex: Instance: For G, Is there a vertex cover of size 4? Yes– Ex: Instance: For G, Is there a vertex cover of size 3? No

vertex cover

Sample Application: place guards within

an art gallery so that all corridors are visible at any

time

Page 15: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Relative difficulty of the two problems

• We don’t know how to solve the independent set problem or vertex cover problem in polynomial time; but we can show that they are equivalently hard

• First we need the following theorem:

Page 16: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Vertex Cover and Independent Set

• Theorem: S is an independent set iff V S is a vertex cover.

Recall: Given a graph G = (V, E), a subset S of the vertices is independent if there are no edges between vertices in S.

Recall: Given a graph G = (V, E), a subset S of the vertices is a vertex cover if every edge in E has at least one endpoint in S.

Page 17: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Vertex Cover and Independent Set

• Theorem: S is an independent set iff V S is a vertex cover

– Let S be any independent set– Consider an arbitrary edge, (u, v) ε E– S independent u S or v S u V S or v V S– Thus, V S covers (u, v)

– Let V S be any vertex cover – Consider two nodes u S and v S – Observe (u, v) E (V S is a vertex cover so if (u,v) ε E, u V-

S or v V – S so u S or v S -- a contradiction – Thus, no two nodes in S are joined by an edge S indep set

Page 18: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Vertex Cover and Independent Set Reductions to each other:

• Theorem: VERTEX-COVER P INDEPENDENT-SET

If we have a black box to solve the Vertex Cover problem then we can decide if G has an independent set of size at least k by asking the black box whether G has a Vertex Cover of size at most n-k.

Conversely if we have a black box to solve the Independent set problem we can decide if G has a vertex cover problem of size at most k by asking the black box if G has an independent set of size at least n-k

Page 19: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Set Cover

• SET COVER: Given a set U of elements, a collection S1, S2, . . . , Sm of subsets of U, and an integer k, does there exist a collection of k of these sets whose union is equal to U?

• Sample application– m available pieces of software– Set U of n capabilities that we would like our system to have

– The ith piece of software provides the set Si U of capabilities

– Goal: achieve all n capabilities using fewest pieces of softwareU = { 1, 2, 3, 4, 5, 6, 7 }

k = 2S1 = {3, 7} S4 = {2, 4}

S2 = {3, 4, 5, 6} S5 = {5}

S3 = {1} S6 = {1, 2, 6,

7}

Page 20: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

• Claim: VERTEX-COVER P SET-COVER

– Pf: Given a VERTEX-COVER instance, i.e., a graph G = (V, E), and an integer, k, we construct a set cover instance whose size equals the size of the vertex cover instance, so G has a vertex cover of size k iff for the set U, and subsets S1, S2, . . . , Sm of U,

there exists a collection of k of these sets whose union is equal to U

Page 21: CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.

Vertex Cover Reduces to Set Cover

• Claim: VERTEX-COVER P SET-COVER

• Construction– Create SET-COVER instance

• k = k, U = { i | ei E), Sv = { i : ei incident to v } (note Sv U)

– Set-cover of size k iff vertex cover of size k

SET COVER

U = { 1, 2, 3, 4, 5, 6, 7 }k = 2Sa = {3, 7} Sb = {2, 4}

Sc = {3, 4, 5, 6} Sd = {5}

Se = {1} Sf= {1, 2, 6, 7}

a

d

b

e

f c

VERTEX COVER

k = 2e1

e2 e3

e5

e4

e6

e7