Top Banner
CSE 421 Median, Approximation Alg Shayan Oveis Gharan 1
41

lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

May 30, 2020

Download

Documents

dariahiddleston
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: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

CSE 421

Median, Approximation Alg

Shayan Oveis Gharan

1

Page 2: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Median

Page 3: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Finding MedianChoose a number ! from "#, … , "&Define• () ! = "+: "+ < !• (. ! = "+: "+ = !• (/ ! = "+: "+ > !

Solve the problem recursively• If 1 ≤ |()(!)|, output (67(() ! , 1)• Else if 1 ≤ () ! + (. ! , output w• Else output (67((/ ! , 1 − |() ! | − |(. ! |)

Can be computed in linear time

Page 4: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

• "# $ ≥ 2 '( = '

*• "+ $ ≥ 2 '

( = '* .

So, what is the running time?

How to lower bound "# $ , |"+ $ |?<

<

<<

<<

<<

<<

<<

<<

<<

<<

<<

≤<w< <<<< < < < < <

< 1

> 1

33 ≤ |"# $ |, "+ $ ≤ 23

3

Page 5: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

• If ! ≤ |$%(')|, output $)*($% ' , !)• Else if ! ≤ $% ' + $- ' , output w• Else output $)*($. ' , ! − $% ' − $- ' )

Where 01 ≤ $% ' , $. ' ≤ 20

1

3 4 = 3 43 + 3 24

3 + 8 4 ⇒ 3 4 = 8(4 log 4)

Asymptotic Running Time?

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

≤<w< <<<< < < < < <

O(nlog n) again? So, what is the point?

Page 6: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Partition into n/5 sets. Sort each set and set ! = #$%('()*+(,-., ,/10)

• #4 ! ≥ 3 789 = :7

89• #; ! ≥ 3 7

89 = :789

< , = < ,5 + < 7,

10 + @ , ⇒ < , = @(,)

An Improved Idea

< <<<< < < < < <

< D

> D

3,10 ≤ |#4 ! |, #; ! ≤ 7,

10

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

<<

Page 7: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

An Improved IdeaSel(S, k) {

! ← #If (n < ??) return ??Partition S into n/5 sets of size 5Sort each set of size 5 and let M be the set of medians, so

|M|=n/5Let w=Sel(M,n/10)For i=1 to n{

If $% < ' add x to #( 'If $% > ' add x to #* 'If $% = ' add x to #,(')

}If (/ ≤ |#( ' |)

return Sel(#( ' , /)else if (/ ≤ #( ' + |#, ' |)

return w;else

return Sel(#* ' , / − #( ' − |#,(')|)}

We can maintain eachset in an array

Page 8: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

D&C SummaryIdea:

“Two halves are better than a whole”• if the base algorithm has super-linear complexity.

“If a little's good, then more's better”• repeat above, recursively

• Applications: Many. • Binary Search, Merge Sort, (Quicksort), • Root of a Function• Closest points, • Integer multiplication• Median• Matrix Multiplication

Page 9: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Approximation Algorithms

Page 10: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Many of the important problems in real world are NP-complete. SAT, Set Cover, Graph Coloring, TSP, Max IND Set, Vertex Cover, …

So, we cannot find optimum solutions in polynomial time.What to do instead?

• Find optimum solution of special cases (e.g., random inputs)

• Find near optimum solution in the worst case

How to deal with NP-complete Problem

Page 11: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Polynomial-time Algorithms with a guaranteed approximation ratio.

! = Cost of computed solutionCost of the optimum

worst case over all instances.

Goal: For each NP-hard problem find an approximation algorithm with the best possible approximation ratio.

Approximation Algorithm

Page 12: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Given a graph G=(V,E), Find smallest set of vertices touching every edge

Vertex Cover

Page 13: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy algorithms are typically used in practice to find a (good) solution to NP-hard problems

Strategy (1): Iteratively, include a vertex that covers most new edges

Q:Does this give an optimum solution?A: No,

Greedy Algorithm?

Page 14: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy (1): Pick vertex that covers the most

!"!# !$!%

Page 15: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy (1): Pick vertex that covers the most

!"!# !$!%

Page 16: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy (1): Pick vertex that covers the most

!"!# !$!%

Page 17: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy (1): Pick vertex that covers the most

!"!# !$!%

Page 18: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy (1): Pick vertex that covers the most

!"!# !$!%

Page 19: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy (1): Pick vertex that covers the most

!"!# !$!%

Page 20: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy (1): Pick vertex that covers the most

!"!# !$!%

Page 21: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy (1): Pick vertex that covers the most

!"!# !$!%

Page 22: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy (1): Pick vertex that covers the most

!"!# !$!%

Page 23: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy (1): Pick vertex that covers the most

!"!# !$!%

Greedy Vertex cover = 20OPT Vertex cover = 8

Page 24: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy (1): Pick vertex that covers the most

|"#| = %/'"( ")"(*)

% vertices. Each vertex has one edge into each "#

Greedy pick bottom vertices = % + (, +

(- + ⋯+ 1 ≈ % ln %

OPT pick top vertices = n

Each vertex in "# has ' edges to top

Page 25: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy 2: Iteratively, pick both endpoints of an uncovered edge.

A Different Greedy Rule

Vertex cover = 6

Page 26: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Greedy 2: Pick Both endpoints of an uncovered edge

!"!# !$!%

Greedy vertex cover = 16

OPT vertex cover = 8

Page 27: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Pf: Suppose Greedy (2) picks endpoints of edges !", … , !%.Since these edges do not touch, every valid cover must pick one vertex from each of these edges!

i.e., '() ≥ +.

But the size of greedy cover is 2k. So, Greedy is a 2-approximation.

Greedy (2) gives 2-approximation

Page 28: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Set CoverGiven a number of sets on a ground set of elements,

Goal: choose minimum number of sets that cover all.

e.g., a company wants to hire employees with certain skills.

Page 29: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Set CoverGiven a number of sets on a ground set of elements,

Goal: choose minimum number of sets that cover all. Set cover = 4

Page 30: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

A Greedy Algorithm

Strategy: Pick the set that maximizes # new elements covered

Page 31: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

A Greedy Algorithm

Strategy: Pick the set that maximizes # new elements covered

Page 32: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

A Greedy Algorithm

Strategy: Pick the set that maximizes # new elements covered

Page 33: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

A Greedy Algorithm

Strategy: Pick the set that maximizes # new elements covered

Page 34: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

A Greedy Algorithm

Strategy: Pick the set that maximizes # new elements covered

Thm: Greedy has ln n approximation ratio

Page 35: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

A Tight Example for Greedy

Page 36: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

A Tight Example for Greedy

Page 37: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

A Tight Example for Greedy

Page 38: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

A Tight Example for Greedy

Page 39: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

A Tight Example for Greedy

Page 40: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

A Tight Example for Greedy

OPT = 2Greedy = 5

Page 41: lecture-15-class - University of Washington · Greedy vertex cover = 16 OPT vertex cover = 8. Thm: Size of greedy (2) vertex cover is at most twice as big as size of optimal cover

Thm: If the best solution has k sets, greedy finds at most k ln(n) sets.

Pf: Suppose OPT=k There is set that covers 1/k fraction of remaining elements, since there are k sets that cover all remaining elements. So in each step, algorithm will cover 1/k fraction of remaining elements.

#elements uncovered after t steps

≤ " 1 − 1%& ≤ "'(

)*

So after & = % ln " steps, # uncovered elements < 1.

Greedy Gives O(log(n)) approximation