Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5...

193
CSE 431/531: Analysis of Algorithms Approximation and Randomized Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo

Transcript of Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5...

Page 1: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

CSE 431/531: Analysis of Algorithms

Approximation and Randomized Algorithms

Lecturer: Shi Li

Department of Computer Science and EngineeringUniversity at Buffalo

Page 2: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

2/58

Outline

1 Approximation Algorithms

2 Approximation Algorithms for Traveling Salesman Problem

3 2-Approximation Algorithm for Vertex Cover

4 78-Approximation Algorithm for Max 3-SAT

5 Randomized QuicksortRecap of QuicksortRandomized Quicksort Algorithm

6 2-Approximation Algorithm for (Weighted) Vertex Cover ViaLinear Programming

Linear Programming2-Approximation for Weighted Vertex Cover

Page 3: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

3/58

Approximation Algorithms

An algorithm for an optimization problem is an α-approximationalgorithm, if it runs in polynomial time, and for any instance tothe problem, it outputs a solution whose cost (or value) is withinan α-factor of the cost (or value) of the optimum solution.

opt: cost (or value) of the optimum solution

sol: cost (or value) of the solution produced by the algorithm

α: approximation ratio

For minimization problems:

α ≥ 1 and we require sol ≤ α · optFor maximization problems, there are two conventions:

α ≤ 1 and we require sol ≥ α · optα ≥ 1 and we require sol ≥ opt/α

Page 4: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

3/58

Approximation Algorithms

An algorithm for an optimization problem is an α-approximationalgorithm, if it runs in polynomial time, and for any instance tothe problem, it outputs a solution whose cost (or value) is withinan α-factor of the cost (or value) of the optimum solution.

opt: cost (or value) of the optimum solution

sol: cost (or value) of the solution produced by the algorithm

α: approximation ratio

For minimization problems:

α ≥ 1 and we require sol ≤ α · optFor maximization problems, there are two conventions:

α ≤ 1 and we require sol ≥ α · optα ≥ 1 and we require sol ≥ opt/α

Page 5: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

3/58

Approximation Algorithms

An algorithm for an optimization problem is an α-approximationalgorithm, if it runs in polynomial time, and for any instance tothe problem, it outputs a solution whose cost (or value) is withinan α-factor of the cost (or value) of the optimum solution.

opt: cost (or value) of the optimum solution

sol: cost (or value) of the solution produced by the algorithm

α: approximation ratio

For minimization problems:

α ≥ 1 and we require sol ≤ α · optFor maximization problems, there are two conventions:

α ≤ 1 and we require sol ≥ α · optα ≥ 1 and we require sol ≥ opt/α

Page 6: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

3/58

Approximation Algorithms

An algorithm for an optimization problem is an α-approximationalgorithm, if it runs in polynomial time, and for any instance tothe problem, it outputs a solution whose cost (or value) is withinan α-factor of the cost (or value) of the optimum solution.

opt: cost (or value) of the optimum solution

sol: cost (or value) of the solution produced by the algorithm

α: approximation ratio

For minimization problems:

α ≥ 1 and we require sol ≤ α · optFor maximization problems, there are two conventions:

α ≤ 1 and we require sol ≥ α · optα ≥ 1 and we require sol ≥ opt/α

Page 7: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

3/58

Approximation Algorithms

An algorithm for an optimization problem is an α-approximationalgorithm, if it runs in polynomial time, and for any instance tothe problem, it outputs a solution whose cost (or value) is withinan α-factor of the cost (or value) of the optimum solution.

opt: cost (or value) of the optimum solution

sol: cost (or value) of the solution produced by the algorithm

α: approximation ratio

For minimization problems:

α ≥ 1 and we require sol ≤ α · opt

For maximization problems, there are two conventions:

α ≤ 1 and we require sol ≥ α · optα ≥ 1 and we require sol ≥ opt/α

Page 8: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

3/58

Approximation Algorithms

An algorithm for an optimization problem is an α-approximationalgorithm, if it runs in polynomial time, and for any instance tothe problem, it outputs a solution whose cost (or value) is withinan α-factor of the cost (or value) of the optimum solution.

opt: cost (or value) of the optimum solution

sol: cost (or value) of the solution produced by the algorithm

α: approximation ratio

For minimization problems:

α ≥ 1 and we require sol ≤ α · optFor maximization problems, there are two conventions:

α ≤ 1 and we require sol ≥ α · optα ≥ 1 and we require sol ≥ opt/α

Page 9: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

4/58

Outline

1 Approximation Algorithms

2 Approximation Algorithms for Traveling Salesman Problem

3 2-Approximation Algorithm for Vertex Cover

4 78-Approximation Algorithm for Max 3-SAT

5 Randomized QuicksortRecap of QuicksortRandomized Quicksort Algorithm

6 2-Approximation Algorithm for (Weighted) Vertex Cover ViaLinear Programming

Linear Programming2-Approximation for Weighted Vertex Cover

Page 10: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

5/58

Recall: Traveling Salesman Problem

A salesman needs to visit n cities1, 2, 3, · · · , nHe needs to start from and returnto city 1

Goal: find a tour with theminimum cost

4

6

2 3

1 2

23

Travelling Salesman Problem (TSP)

Input: a graph G = (V,E), weights w : E → R≥0

Output: a traveling-salesman tour with the minimum cost

Page 11: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

5/58

Recall: Traveling Salesman Problem

A salesman needs to visit n cities1, 2, 3, · · · , nHe needs to start from and returnto city 1

Goal: find a tour with theminimum cost

4

6

2 3

1 2

23

Travelling Salesman Problem (TSP)

Input: a graph G = (V,E), weights w : E → R≥0

Output: a traveling-salesman tour with the minimum cost

Page 12: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

5/58

Recall: Traveling Salesman Problem

A salesman needs to visit n cities1, 2, 3, · · · , nHe needs to start from and returnto city 1

Goal: find a tour with theminimum cost

4

6

2 3

1 2

23

Travelling Salesman Problem (TSP)

Input: a graph G = (V,E), weights w : E → R≥0

Output: a traveling-salesman tour with the minimum cost

Page 13: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

5/58

Recall: Traveling Salesman Problem

A salesman needs to visit n cities1, 2, 3, · · · , nHe needs to start from and returnto city 1

Goal: find a tour with theminimum cost

4

6

2 3

1 2

23

Travelling Salesman Problem (TSP)

Input: a graph G = (V,E), weights w : E → R≥0

Output: a traveling-salesman tour with the minimum cost

Page 14: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

5/58

Recall: Traveling Salesman Problem

A salesman needs to visit n cities1, 2, 3, · · · , nHe needs to start from and returnto city 1

Goal: find a tour with theminimum cost

4

6

2 3

1 2

23

Travelling Salesman Problem (TSP)

Input: a graph G = (V,E), weights w : E → R≥0

Output: a traveling-salesman tour with the minimum cost

Page 15: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

5/58

Recall: Traveling Salesman Problem

A salesman needs to visit n cities1, 2, 3, · · · , nHe needs to start from and returnto city 1

Goal: find a tour with theminimum cost

4

6

2 3

1 2

23

Travelling Salesman Problem (TSP)

Input: a graph G = (V,E), weights w : E → R≥0

Output: a traveling-salesman tour with the minimum cost

Page 16: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

5/58

Recall: Traveling Salesman Problem

A salesman needs to visit n cities1, 2, 3, · · · , nHe needs to start from and returnto city 1

Goal: find a tour with theminimum cost

4

6

2 3

1 2

23

Travelling Salesman Problem (TSP)

Input: a graph G = (V,E), weights w : E → R≥0

Output: a traveling-salesman tour with the minimum cost

Page 17: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

5/58

Recall: Traveling Salesman Problem

A salesman needs to visit n cities1, 2, 3, · · · , nHe needs to start from and returnto city 1

Goal: find a tour with theminimum cost

4

6

2 3

1 2

23

Travelling Salesman Problem (TSP)

Input: a graph G = (V,E), weights w : E → R≥0

Output: a traveling-salesman tour with the minimum cost

Page 18: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 19: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 20: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 21: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 22: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 23: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 24: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 25: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 26: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 27: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 28: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 29: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 30: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 31: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 32: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 33: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 34: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 35: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 36: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 37: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 38: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 39: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

6/58

2-Approximation Algorithm for TSP

TSP1(G,w)

1 MST ← the minimumspanning tree of G w.r.tweights w, returned byeither Kruskal’s algorithm orPrim’s algorithm.

2 Output tour formed bymaking two copies of eachedge in MST .

a

b

d

h

e

i

c

f g

j k

Page 40: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

7/58

2-Approximation Algorithm for TSP

Lemma Algorithm TSP1 is a 2-approximation algorithm forTSP.

Proof

mst = cost of the minimum spanning tree

tsp = cost of the optimum travelling salesman tour

then mst ≤ tsp, since removing one edge from the optimumtravelling salesman tour results in a spanning tree

sol = cost of tour given by algorithm TSP1

sol = 2 ·mst ≤ 2 · tsp.

Page 41: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

7/58

2-Approximation Algorithm for TSP

Lemma Algorithm TSP1 is a 2-approximation algorithm forTSP.

Proof

mst = cost of the minimum spanning tree

tsp = cost of the optimum travelling salesman tour

then mst ≤ tsp, since removing one edge from the optimumtravelling salesman tour results in a spanning tree

sol = cost of tour given by algorithm TSP1

sol = 2 ·mst ≤ 2 · tsp.

Page 42: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

7/58

2-Approximation Algorithm for TSP

Lemma Algorithm TSP1 is a 2-approximation algorithm forTSP.

Proof

mst = cost of the minimum spanning tree

tsp = cost of the optimum travelling salesman tour

then mst ≤ tsp, since removing one edge from the optimumtravelling salesman tour results in a spanning tree

sol = cost of tour given by algorithm TSP1

sol = 2 ·mst ≤ 2 · tsp.

Page 43: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

7/58

2-Approximation Algorithm for TSP

Lemma Algorithm TSP1 is a 2-approximation algorithm forTSP.

Proof

mst = cost of the minimum spanning tree

tsp = cost of the optimum travelling salesman tour

then mst ≤ tsp, since removing one edge from the optimumtravelling salesman tour results in a spanning tree

sol = cost of tour given by algorithm TSP1

sol = 2 ·mst ≤ 2 · tsp.

Page 44: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

7/58

2-Approximation Algorithm for TSP

Lemma Algorithm TSP1 is a 2-approximation algorithm forTSP.

Proof

mst = cost of the minimum spanning tree

tsp = cost of the optimum travelling salesman tour

then mst ≤ tsp, since removing one edge from the optimumtravelling salesman tour results in a spanning tree

sol = cost of tour given by algorithm TSP1

sol = 2 ·mst ≤ 2 · tsp.

Page 45: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

7/58

2-Approximation Algorithm for TSP

Lemma Algorithm TSP1 is a 2-approximation algorithm forTSP.

Proof

mst = cost of the minimum spanning tree

tsp = cost of the optimum travelling salesman tour

then mst ≤ tsp, since removing one edge from the optimumtravelling salesman tour results in a spanning tree

sol = cost of tour given by algorithm TSP1

sol = 2 ·mst ≤ 2 · tsp.

Page 46: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

8/58

1.5-Approximation for TSP

Def. Given G = (V,E), a set U ⊆ V of even number ofvertices in V , a matching M over U in G is a set of |U |/2 pathsin G, such that every vertex in U is one end point of some path.

Def. The cost of the matching M , denoted as cost(M) is thetotal cost of all edges in the |U |/2 paths (countingmultiplicities).

Theorem Given G = (V,E), a set U ⊆ V of even number ofverticies, the minimum cost matching over U in G can be foundin polynomial time.

Page 47: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

9/58

1.5-Approximation for TSP

Lemma Let T be a spanning tree of G = (V,E); let U be theset of odd-degree vertices in MST (|U | must be even, why?). LetM be a matching over U , then, T ]M gives a travelingsalesman’s tour.

Proof.

Every vertex in T ]M has even degree and T ]M is connected(since it contains the spanning tree). Thus T ]M is an Euleriangraph and we can find a tour that visits every edge in T ]Mexactly once.

Page 48: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

10/58

1.5-Approximation for TSP

Lemma Let U be a set of evennumber of vertices in G. Thenthe cost of the cheapestmatching over U in G is at most12tsp.

points in U

optimum TSP

Proof.

Take the optimum TSP

Breaking into read matching and blue matching over U

cost(blue matching)+ cost(red matching) = tsp

Thus, cost(blue matching) ≤ 12tsp or

cost(red matching) ≤ 12tsp

cost(cheapeast matching) ≤ 12tsp

Page 49: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

10/58

1.5-Approximation for TSP

Lemma Let U be a set of evennumber of vertices in G. Thenthe cost of the cheapestmatching over U in G is at most12tsp.

points in U

optimum TSP

Proof.

Take the optimum TSP

Breaking into read matching and blue matching over U

cost(blue matching)+ cost(red matching) = tsp

Thus, cost(blue matching) ≤ 12tsp or

cost(red matching) ≤ 12tsp

cost(cheapeast matching) ≤ 12tsp

Page 50: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

10/58

1.5-Approximation for TSP

Lemma Let U be a set of evennumber of vertices in G. Thenthe cost of the cheapestmatching over U in G is at most12tsp.

points in U

optimum TSP

Proof.

Take the optimum TSP

Breaking into read matching and blue matching over U

cost(blue matching)+ cost(red matching) = tsp

Thus, cost(blue matching) ≤ 12tsp or

cost(red matching) ≤ 12tsp

cost(cheapeast matching) ≤ 12tsp

Page 51: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

10/58

1.5-Approximation for TSP

Lemma Let U be a set of evennumber of vertices in G. Thenthe cost of the cheapestmatching over U in G is at most12tsp.

points in U

optimum TSP

Proof.

Take the optimum TSP

Breaking into read matching and blue matching over U

cost(blue matching)+ cost(red matching) = tsp

Thus, cost(blue matching) ≤ 12tsp or

cost(red matching) ≤ 12tsp

cost(cheapeast matching) ≤ 12tsp

Page 52: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

10/58

1.5-Approximation for TSP

Lemma Let U be a set of evennumber of vertices in G. Thenthe cost of the cheapestmatching over U in G is at most12tsp.

points in U

optimum TSP

Proof.

Take the optimum TSP

Breaking into read matching and blue matching over U

cost(blue matching)+ cost(red matching) = tsp

Thus, cost(blue matching) ≤ 12tsp or

cost(red matching) ≤ 12tsp

cost(cheapeast matching) ≤ 12tsp

Page 53: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

11/58

Outline

1 Approximation Algorithms

2 Approximation Algorithms for Traveling Salesman Problem

3 2-Approximation Algorithm for Vertex Cover

4 78-Approximation Algorithm for Max 3-SAT

5 Randomized QuicksortRecap of QuicksortRandomized Quicksort Algorithm

6 2-Approximation Algorithm for (Weighted) Vertex Cover ViaLinear Programming

Linear Programming2-Approximation for Weighted Vertex Cover

Page 54: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

12/58

Vertex Cover Problem

Def. Given a graph G = (V,E), a vertex cover of G is a subsetS ⊆ V such that for every (u, v) ∈ E then u ∈ S or v ∈ S .

Vertex-Cover Problem

Input: G = (V,E)

Output: a vertex cover S with minimum |S|

Page 55: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

12/58

Vertex Cover Problem

Def. Given a graph G = (V,E), a vertex cover of G is a subsetS ⊆ V such that for every (u, v) ∈ E then u ∈ S or v ∈ S .

Vertex-Cover Problem

Input: G = (V,E)

Output: a vertex cover S with minimum |S|

Page 56: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

13/58

First Try: Greedy Algorithm

Greedy Algorithm for Vertex-Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let v be the vertex of the maximum degree in (V,E ′)

4 S ← S ∪ v,5 remove all edges incident to v from E ′

6 output S

Theorem Greedy algorithm is an O(lg n)-approximation forvertex-cover.

We are not going to prove the theorem

Instead, we show that the O(lg n)-approximation ratio istight for the algorithm

Page 57: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

13/58

First Try: Greedy Algorithm

Greedy Algorithm for Vertex-Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let v be the vertex of the maximum degree in (V,E ′)

4 S ← S ∪ v,5 remove all edges incident to v from E ′

6 output S

Theorem Greedy algorithm is an O(lg n)-approximation forvertex-cover.

We are not going to prove the theorem

Instead, we show that the O(lg n)-approximation ratio istight for the algorithm

Page 58: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

13/58

First Try: Greedy Algorithm

Greedy Algorithm for Vertex-Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let v be the vertex of the maximum degree in (V,E ′)

4 S ← S ∪ v,5 remove all edges incident to v from E ′

6 output S

Theorem Greedy algorithm is an O(lg n)-approximation forvertex-cover.

We are not going to prove the theorem

Instead, we show that the O(lg n)-approximation ratio istight for the algorithm

Page 59: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

13/58

First Try: Greedy Algorithm

Greedy Algorithm for Vertex-Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let v be the vertex of the maximum degree in (V,E ′)

4 S ← S ∪ v,5 remove all edges incident to v from E ′

6 output S

Theorem Greedy algorithm is an O(lg n)-approximation forvertex-cover.

We are not going to prove the theorem

Instead, we show that the O(lg n)-approximation ratio istight for the algorithm

Page 60: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

14/58

Bad Example for Greedy Algorithm

|L| = n′

L: n′ vertices

R2: bn′/2c vertices, each connected to 2 vertices in L

R3: bn′/3c vertices, each connected to 3 vertices in L

R4: bn′/4c vertices, each connected to 4 vertices in L

· · ·Rn′ : 1 vertex, connected to n′ vertices in L

R = R2 ∪R3 ∪ · · · ∪Rn′

Page 61: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

14/58

Bad Example for Greedy Algorithm

R2

|L| = n′

L: n′ vertices

R2: bn′/2c vertices, each connected to 2 vertices in L

R3: bn′/3c vertices, each connected to 3 vertices in L

R4: bn′/4c vertices, each connected to 4 vertices in L

· · ·Rn′ : 1 vertex, connected to n′ vertices in L

R = R2 ∪R3 ∪ · · · ∪Rn′

Page 62: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

14/58

Bad Example for Greedy Algorithm

R2 R3

|L| = n′

L: n′ vertices

R2: bn′/2c vertices, each connected to 2 vertices in L

R3: bn′/3c vertices, each connected to 3 vertices in L

R4: bn′/4c vertices, each connected to 4 vertices in L

· · ·Rn′ : 1 vertex, connected to n′ vertices in L

R = R2 ∪R3 ∪ · · · ∪Rn′

Page 63: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

14/58

Bad Example for Greedy Algorithm

R2 R3 R4

|L| = n′

L: n′ vertices

R2: bn′/2c vertices, each connected to 2 vertices in L

R3: bn′/3c vertices, each connected to 3 vertices in L

R4: bn′/4c vertices, each connected to 4 vertices in L

· · ·Rn′ : 1 vertex, connected to n′ vertices in L

R = R2 ∪R3 ∪ · · · ∪Rn′

Page 64: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

14/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

Rn′

L: n′ vertices

R2: bn′/2c vertices, each connected to 2 vertices in L

R3: bn′/3c vertices, each connected to 3 vertices in L

R4: bn′/4c vertices, each connected to 4 vertices in L

· · ·Rn′ : 1 vertex, connected to n′ vertices in L

R = R2 ∪R3 ∪ · · · ∪Rn′

Page 65: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

14/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

L: n′ vertices

R2: bn′/2c vertices, each connected to 2 vertices in L

R3: bn′/3c vertices, each connected to 3 vertices in L

R4: bn′/4c vertices, each connected to 4 vertices in L

· · ·Rn′ : 1 vertex, connected to n′ vertices in L

R = R2 ∪R3 ∪ · · · ∪Rn′

Page 66: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

15/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

Optimum solution is L, where |L| = n′

Greedy algorithm picks Rn′ , Rn′−1, · · · , R2 in this order

Thus, greedy algorithm outputs R

|R| =n∑

i=2

⌊n′

i

⌋≥

n∑i=1

n′

i− n′ − (n′ − 1)

= n′H(n′)− (2n′ − 1) = Ω(n′ lg n′)

where H(n′) = 1 + 12

+ 13

+ · · ·+ 1n′ = Θ(lg n′) is the n′-th

number in the harmonic sequence.

Page 67: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

15/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

Optimum solution is L, where |L| = n′

Greedy algorithm picks Rn′ , Rn′−1, · · · , R2 in this order

Thus, greedy algorithm outputs R

|R| =n∑

i=2

⌊n′

i

⌋≥

n∑i=1

n′

i− n′ − (n′ − 1)

= n′H(n′)− (2n′ − 1) = Ω(n′ lg n′)

where H(n′) = 1 + 12

+ 13

+ · · ·+ 1n′ = Θ(lg n′) is the n′-th

number in the harmonic sequence.

Page 68: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

15/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

Optimum solution is L, where |L| = n′

Greedy algorithm picks Rn′ , Rn′−1, · · · , R2 in this order

Thus, greedy algorithm outputs R

|R| =n∑

i=2

⌊n′

i

⌋≥

n∑i=1

n′

i− n′ − (n′ − 1)

= n′H(n′)− (2n′ − 1) = Ω(n′ lg n′)

where H(n′) = 1 + 12

+ 13

+ · · ·+ 1n′ = Θ(lg n′) is the n′-th

number in the harmonic sequence.

Page 69: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

15/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

Optimum solution is L, where |L| = n′

Greedy algorithm picks Rn′ , Rn′−1, · · · , R2 in this order

Thus, greedy algorithm outputs R

|R| =n∑

i=2

⌊n′

i

⌋≥

n∑i=1

n′

i− n′ − (n′ − 1)

= n′H(n′)− (2n′ − 1) = Ω(n′ lg n′)

where H(n′) = 1 + 12

+ 13

+ · · ·+ 1n′ = Θ(lg n′) is the n′-th

number in the harmonic sequence.

Page 70: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

15/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

Optimum solution is L, where |L| = n′

Greedy algorithm picks Rn′ , Rn′−1, · · · , R2 in this order

Thus, greedy algorithm outputs R

|R| =n∑

i=2

⌊n′

i

⌋≥

n∑i=1

n′

i− n′ − (n′ − 1)

= n′H(n′)− (2n′ − 1) = Ω(n′ lg n′)

where H(n′) = 1 + 12

+ 13

+ · · ·+ 1n′ = Θ(lg n′) is the n′-th

number in the harmonic sequence.

Page 71: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

15/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

Optimum solution is L, where |L| = n′

Greedy algorithm picks Rn′ , Rn′−1, · · · , R2 in this order

Thus, greedy algorithm outputs R

|R| =n∑

i=2

⌊n′

i

⌋≥

n∑i=1

n′

i− n′ − (n′ − 1)

= n′H(n′)− (2n′ − 1) = Ω(n′ lg n′)

where H(n′) = 1 + 12

+ 13

+ · · ·+ 1n′ = Θ(lg n′) is the n′-th

number in the harmonic sequence.

Page 72: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

16/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

Let n = |L ∪R| = Θ(n′ lg n′)

Then lg n = Θ(lg n′)|R||L| = Ω(n′ lgn′)

n′ = Ω(lg n′) = Ω(lg n).

Thus, greedy algorithm does not do better than O(lg n).

Page 73: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

16/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

Let n = |L ∪R| = Θ(n′ lg n′)

Then lg n = Θ(lg n′)|R||L| = Ω(n′ lgn′)

n′ = Ω(lg n′) = Ω(lg n).

Thus, greedy algorithm does not do better than O(lg n).

Page 74: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

16/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

Let n = |L ∪R| = Θ(n′ lg n′)

Then lg n = Θ(lg n′)

|R||L| = Ω(n′ lgn′)

n′ = Ω(lg n′) = Ω(lg n).

Thus, greedy algorithm does not do better than O(lg n).

Page 75: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

16/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

Let n = |L ∪R| = Θ(n′ lg n′)

Then lg n = Θ(lg n′)|R||L| = Ω(n′ lgn′)

n′ = Ω(lg n′) = Ω(lg n).

Thus, greedy algorithm does not do better than O(lg n).

Page 76: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

16/58

Bad Example for Greedy Algorithm

R2 R3 R4 R5

|L| = n′

RRn′

Let n = |L ∪R| = Θ(n′ lg n′)

Then lg n = Θ(lg n′)|R||L| = Ω(n′ lgn′)

n′ = Ω(lg n′) = Ω(lg n).

Thus, greedy algorithm does not do better than O(lg n).

Page 77: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

17/58

Greedy algorithm is a very natural algorithm, which might bethe first algorithm some one can come up with

However, the approximation ratio is not so good

We now give a somewhat “counter-intuitive” algorithm,

for which we can prove a 2-approximation ratio.

Page 78: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

17/58

Greedy algorithm is a very natural algorithm, which might bethe first algorithm some one can come up with

However, the approximation ratio is not so good

We now give a somewhat “counter-intuitive” algorithm,

for which we can prove a 2-approximation ratio.

Page 79: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

17/58

Greedy algorithm is a very natural algorithm, which might bethe first algorithm some one can come up with

However, the approximation ratio is not so good

We now give a somewhat “counter-intuitive” algorithm,

for which we can prove a 2-approximation ratio.

Page 80: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

17/58

Greedy algorithm is a very natural algorithm, which might bethe first algorithm some one can come up with

However, the approximation ratio is not so good

We now give a somewhat “counter-intuitive” algorithm,

for which we can prove a 2-approximation ratio.

Page 81: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

18/58

2-Approximation Algorithm for Vertex Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let (u, v) be any edge in E ′

4 S ← S ∪ u, v,5 remove all edges incident to u and v from E ′

6 output S

The counter-intuitive part: adding both u and v to S seemsto be wasteful

Intuition for the 2-approximation ratio: the optimum solutionmust cover the edge (u, v), using either u or v. If we selectboth, we are always ahead of the optimum solution. Theapproximation factor we lost is at most 2.

Page 82: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

18/58

2-Approximation Algorithm for Vertex Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let (u, v) be any edge in E ′

4 S ← S ∪ u, v,5 remove all edges incident to u and v from E ′

6 output S

The counter-intuitive part: adding both u and v to S seemsto be wasteful

Intuition for the 2-approximation ratio: the optimum solutionmust cover the edge (u, v), using either u or v. If we selectboth, we are always ahead of the optimum solution. Theapproximation factor we lost is at most 2.

Page 83: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

18/58

2-Approximation Algorithm for Vertex Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let (u, v) be any edge in E ′

4 S ← S ∪ u, v,5 remove all edges incident to u and v from E ′

6 output S

The counter-intuitive part: adding both u and v to S seemsto be wasteful

Intuition for the 2-approximation ratio: the optimum solutionmust cover the edge (u, v), using either u or v. If we selectboth, we are always ahead of the optimum solution. Theapproximation factor we lost is at most 2.

Page 84: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

19/58

2-Approximation Algorithm for Vertex Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let (u, v) be any edge in E ′

4 S ← S ∪ u, v,5 remove all edges incident to u and v from E ′

6 output S

Let E∗ be the set of edges (u, v) considered in Statement 3

Observation: E∗ is a matching and |S| = 2|E∗|To cover all edges in E∗, the optimum solution needs |E∗|vertices

Theorem The algorithm is a 2-approximation algorithm forvertex-cover.

Page 85: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

19/58

2-Approximation Algorithm for Vertex Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let (u, v) be any edge in E ′

4 S ← S ∪ u, v,5 remove all edges incident to u and v from E ′

6 output S

Let E∗ be the set of edges (u, v) considered in Statement 3

Observation: E∗ is a matching and |S| = 2|E∗|To cover all edges in E∗, the optimum solution needs |E∗|vertices

Theorem The algorithm is a 2-approximation algorithm forvertex-cover.

Page 86: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

19/58

2-Approximation Algorithm for Vertex Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let (u, v) be any edge in E ′

4 S ← S ∪ u, v,5 remove all edges incident to u and v from E ′

6 output S

Let E∗ be the set of edges (u, v) considered in Statement 3

Observation: E∗ is a matching and |S| = 2|E∗|

To cover all edges in E∗, the optimum solution needs |E∗|vertices

Theorem The algorithm is a 2-approximation algorithm forvertex-cover.

Page 87: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

19/58

2-Approximation Algorithm for Vertex Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let (u, v) be any edge in E ′

4 S ← S ∪ u, v,5 remove all edges incident to u and v from E ′

6 output S

Let E∗ be the set of edges (u, v) considered in Statement 3

Observation: E∗ is a matching and |S| = 2|E∗|To cover all edges in E∗, the optimum solution needs |E∗|vertices

Theorem The algorithm is a 2-approximation algorithm forvertex-cover.

Page 88: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

19/58

2-Approximation Algorithm for Vertex Cover

1 E ′ ← E, S ← ∅2 while E ′ 6= ∅3 let (u, v) be any edge in E ′

4 S ← S ∪ u, v,5 remove all edges incident to u and v from E ′

6 output S

Let E∗ be the set of edges (u, v) considered in Statement 3

Observation: E∗ is a matching and |S| = 2|E∗|To cover all edges in E∗, the optimum solution needs |E∗|vertices

Theorem The algorithm is a 2-approximation algorithm forvertex-cover.

Page 89: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

20/58

Outline

1 Approximation Algorithms

2 Approximation Algorithms for Traveling Salesman Problem

3 2-Approximation Algorithm for Vertex Cover

4 78-Approximation Algorithm for Max 3-SAT

5 Randomized QuicksortRecap of QuicksortRandomized Quicksort Algorithm

6 2-Approximation Algorithm for (Weighted) Vertex Cover ViaLinear Programming

Linear Programming2-Approximation for Weighted Vertex Cover

Page 90: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

21/58

Max 3-SAT

Input: n boolean variables x1, x2, · · · , xnm clauses, each clause is a disjunction of 3 literalsfrom 3 distinct variables

Output: an assignment so as to satisfy as many clauses aspossible

Example:

clauses: x2 ∨ ¬x3 ∨ ¬x4, x2 ∨ x3 ∨ ¬x4,¬x1 ∨ x2 ∨ x4, x1 ∨ ¬x2 ∨ x3, ¬x1 ∨ ¬x2 ∨ ¬x4

We can satisfy all the 5 clauses: x = (1, 1, 1, 0, 1)

Page 91: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

22/58

Randomized Algorithm for Max 3-SAT

Simple idea: randomly set each variable xu = 1 withprobability 1/2, independent of other variables

Lemma Let m be the number of clauses. Then, in expectation,78m number of clauses will be satisfied.

Proof.

for each clause Cj, let Zj = 1 if Cj is satisfied and 0otherwise

Z =∑m

j=1 Zj is the total number of satisfied clauses

E[Zj] = 7/8: out of 8 possible assignments to the 3 variablesin Cj, 7 of them will make Cj satisfied

E[Z] = E[∑m

j=1 Zj

]=∑m

j=1 E[Zj] =∑m

j=178

= 78m, by

linearity of expectation.

Page 92: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

22/58

Randomized Algorithm for Max 3-SAT

Simple idea: randomly set each variable xu = 1 withprobability 1/2, independent of other variables

Lemma Let m be the number of clauses. Then, in expectation,78m number of clauses will be satisfied.

Proof.

for each clause Cj, let Zj = 1 if Cj is satisfied and 0otherwise

Z =∑m

j=1 Zj is the total number of satisfied clauses

E[Zj] = 7/8: out of 8 possible assignments to the 3 variablesin Cj, 7 of them will make Cj satisfied

E[Z] = E[∑m

j=1 Zj

]=∑m

j=1 E[Zj] =∑m

j=178

= 78m, by

linearity of expectation.

Page 93: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

22/58

Randomized Algorithm for Max 3-SAT

Simple idea: randomly set each variable xu = 1 withprobability 1/2, independent of other variables

Lemma Let m be the number of clauses. Then, in expectation,78m number of clauses will be satisfied.

Proof.

for each clause Cj, let Zj = 1 if Cj is satisfied and 0otherwise

Z =∑m

j=1 Zj is the total number of satisfied clauses

E[Zj] = 7/8: out of 8 possible assignments to the 3 variablesin Cj, 7 of them will make Cj satisfied

E[Z] = E[∑m

j=1 Zj

]=∑m

j=1 E[Zj] =∑m

j=178

= 78m, by

linearity of expectation.

Page 94: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

22/58

Randomized Algorithm for Max 3-SAT

Simple idea: randomly set each variable xu = 1 withprobability 1/2, independent of other variables

Lemma Let m be the number of clauses. Then, in expectation,78m number of clauses will be satisfied.

Proof.

for each clause Cj, let Zj = 1 if Cj is satisfied and 0otherwise

Z =∑m

j=1 Zj is the total number of satisfied clauses

E[Zj] = 7/8: out of 8 possible assignments to the 3 variablesin Cj, 7 of them will make Cj satisfied

E[Z] = E[∑m

j=1 Zj

]=∑m

j=1 E[Zj] =∑m

j=178

= 78m, by

linearity of expectation.

Page 95: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

22/58

Randomized Algorithm for Max 3-SAT

Simple idea: randomly set each variable xu = 1 withprobability 1/2, independent of other variables

Lemma Let m be the number of clauses. Then, in expectation,78m number of clauses will be satisfied.

Proof.

for each clause Cj, let Zj = 1 if Cj is satisfied and 0otherwise

Z =∑m

j=1 Zj is the total number of satisfied clauses

E[Zj] = 7/8: out of 8 possible assignments to the 3 variablesin Cj, 7 of them will make Cj satisfied

E[Z] = E[∑m

j=1 Zj

]=∑m

j=1 E[Zj] =∑m

j=178

= 78m, by

linearity of expectation.

Page 96: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

22/58

Randomized Algorithm for Max 3-SAT

Simple idea: randomly set each variable xu = 1 withprobability 1/2, independent of other variables

Lemma Let m be the number of clauses. Then, in expectation,78m number of clauses will be satisfied.

Proof.

for each clause Cj, let Zj = 1 if Cj is satisfied and 0otherwise

Z =∑m

j=1 Zj is the total number of satisfied clauses

E[Zj] = 7/8: out of 8 possible assignments to the 3 variablesin Cj, 7 of them will make Cj satisfied

E[Z] = E[∑m

j=1 Zj

]=∑m

j=1 E[Zj] =∑m

j=178

= 78m, by

linearity of expectation.

Page 97: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

22/58

Randomized Algorithm for Max 3-SAT

Simple idea: randomly set each variable xu = 1 withprobability 1/2, independent of other variables

Lemma Let m be the number of clauses. Then, in expectation,78m number of clauses will be satisfied.

Proof.

for each clause Cj, let Zj = 1 if Cj is satisfied and 0otherwise

Z =∑m

j=1 Zj is the total number of satisfied clauses

E[Zj] = 7/8: out of 8 possible assignments to the 3 variablesin Cj, 7 of them will make Cj satisfied

E[Z] = E[∑m

j=1 Zj

]=∑m

j=1 E[Zj] =∑m

j=178

= 78m, by

linearity of expectation.

Page 98: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

23/58

Randomized Algorithm for Max 3-SAT

Lemma Let m be the number of clauses. Then, in expectation,78m number of clauses will be satisfied.

Since the optimum solution can satisfy at most m clauses,lemma gives a randomized 7/8-approximation forMax-3-SAT.

Theorem ([Hastad 97]) Unless P = NP, there is noρ-approximation algorithm for MAX-3-SAT for any ρ > 7/8.

Page 99: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

23/58

Randomized Algorithm for Max 3-SAT

Lemma Let m be the number of clauses. Then, in expectation,78m number of clauses will be satisfied.

Since the optimum solution can satisfy at most m clauses,lemma gives a randomized 7/8-approximation forMax-3-SAT.

Theorem ([Hastad 97]) Unless P = NP, there is noρ-approximation algorithm for MAX-3-SAT for any ρ > 7/8.

Page 100: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

23/58

Randomized Algorithm for Max 3-SAT

Lemma Let m be the number of clauses. Then, in expectation,78m number of clauses will be satisfied.

Since the optimum solution can satisfy at most m clauses,lemma gives a randomized 7/8-approximation forMax-3-SAT.

Theorem ([Hastad 97]) Unless P = NP, there is noρ-approximation algorithm for MAX-3-SAT for any ρ > 7/8.

Page 101: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

24/58

Outline

1 Approximation Algorithms

2 Approximation Algorithms for Traveling Salesman Problem

3 2-Approximation Algorithm for Vertex Cover

4 78-Approximation Algorithm for Max 3-SAT

5 Randomized QuicksortRecap of QuicksortRandomized Quicksort Algorithm

6 2-Approximation Algorithm for (Weighted) Vertex Cover ViaLinear Programming

Linear Programming2-Approximation for Weighted Vertex Cover

Page 102: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

25/58

Outline

1 Approximation Algorithms

2 Approximation Algorithms for Traveling Salesman Problem

3 2-Approximation Algorithm for Vertex Cover

4 78-Approximation Algorithm for Max 3-SAT

5 Randomized QuicksortRecap of QuicksortRandomized Quicksort Algorithm

6 2-Approximation Algorithm for (Weighted) Vertex Cover ViaLinear Programming

Linear Programming2-Approximation for Weighted Vertex Cover

Page 103: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

26/58

Quicksort vs Merge-Sort

Merge Sort QuicksortDivide Trivial Separate small and big numbers

Conquer Recurse RecurseCombine Merge 2 sorted arrays Trivial

Page 104: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

27/58

Quicksort Example

Assumption We can choose median of an array of size n inO(n) time.

1582 75 6938 179464 25 7629 92 3745 85

Page 105: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

27/58

Quicksort Example

Assumption We can choose median of an array of size n inO(n) time.

1582 75 6938 179464 25 7629 92 3745 8564

Page 106: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

27/58

Quicksort Example

Assumption We can choose median of an array of size n inO(n) time.

1582 75 6938 179464 25 7629 92 3745 8564

15 82 75 6938 17 9425 7629 923745 8564

Page 107: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

27/58

Quicksort Example

Assumption We can choose median of an array of size n inO(n) time.

1582 75 6938 179464 25 7629 92 3745 8564

15 82 75 6938 17 9425 7629 923745 856429

Page 108: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

27/58

Quicksort Example

Assumption We can choose median of an array of size n inO(n) time.

1582 75 6938 179464 25 7629 92 3745 8564

15 82 75 6938 17 9425 7629 923745 856429

15 82 75 693817 9425 76923745 856429

Page 109: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

28/58

Quicksort

quicksort(A, n)

1 if n ≤ 1 then return A

2 x← lower median of A

3 AL ← elements in A that are less than x \\ Divide

4 AR ← elements in A that are greater than x \\ Divide

5 BL ← quicksort(AL, AL.size) \\ Conquer

6 BR ← quicksort(AR, AR.size) \\ Conquer

7 t← number of times x appear A

8 return the array obtained by concatenating BL, the arraycontaining t copies of x, and BR

Recurrence T (n) ≤ 2T (n/2) +O(n)

Running time = O(n lg n)

Page 110: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

28/58

Quicksort

quicksort(A, n)

1 if n ≤ 1 then return A

2 x← lower median of A

3 AL ← elements in A that are less than x \\ Divide

4 AR ← elements in A that are greater than x \\ Divide

5 BL ← quicksort(AL, AL.size) \\ Conquer

6 BR ← quicksort(AR, AR.size) \\ Conquer

7 t← number of times x appear A

8 return the array obtained by concatenating BL, the arraycontaining t copies of x, and BR

Recurrence T (n) ≤ 2T (n/2) +O(n)

Running time = O(n lg n)

Page 111: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

28/58

Quicksort

quicksort(A, n)

1 if n ≤ 1 then return A

2 x← lower median of A

3 AL ← elements in A that are less than x \\ Divide

4 AR ← elements in A that are greater than x \\ Divide

5 BL ← quicksort(AL, AL.size) \\ Conquer

6 BR ← quicksort(AR, AR.size) \\ Conquer

7 t← number of times x appear A

8 return the array obtained by concatenating BL, the arraycontaining t copies of x, and BR

Recurrence T (n) ≤ 2T (n/2) +O(n)

Running time = O(n lg n)

Page 112: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

29/58

n

n/2 n/2

n/4 n/4 n/4 n/4

n/8 n/8 n/8 n/8 n/8 n/8 n/8 n/8

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

Each level has total running time O(n)

Number of levels = O(lg n)

Total running time = O(n lg n)

Page 113: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 856429 17

To partition the array into two parts, we only need O(1)extra space.

Page 114: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 856429 17

To partition the array into two parts, we only need O(1)extra space.

Page 115: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 29 17

To partition the array into two parts, we only need O(1)extra space.

Page 116: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 29

i j

17

To partition the array into two parts, we only need O(1)extra space.

Page 117: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 29

i j

17

To partition the array into two parts, we only need O(1)extra space.

Page 118: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 29

i j

17 1764

To partition the array into two parts, we only need O(1)extra space.

Page 119: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764

i j

To partition the array into two parts, we only need O(1)extra space.

Page 120: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764

i j

8264

To partition the array into two parts, we only need O(1)extra space.

Page 121: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 17648264

i j

To partition the array into two parts, we only need O(1)extra space.

Page 122: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 17648264

i j

37 64

To partition the array into two parts, we only need O(1)extra space.

Page 123: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 64

i j

To partition the array into two parts, we only need O(1)extra space.

Page 124: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 64

i j

7564

To partition the array into two parts, we only need O(1)extra space.

Page 125: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 647564

ji

To partition the array into two parts, we only need O(1)extra space.

Page 126: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 647564

ji

15 64

To partition the array into two parts, we only need O(1)extra space.

Page 127: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 64756415 64

i j

To partition the array into two parts, we only need O(1)extra space.

Page 128: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 64756415 64

i j

9464

To partition the array into two parts, we only need O(1)extra space.

Page 129: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 64756415 649464

i j

To partition the array into two parts, we only need O(1)extra space.

Page 130: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 64756415 649464

i j

25 64

To partition the array into two parts, we only need O(1)extra space.

Page 131: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 64756415 64946425 64

i j

To partition the array into two parts, we only need O(1)extra space.

Page 132: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 64756415 64946425 64

i j

64 69

To partition the array into two parts, we only need O(1)extra space.

Page 133: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 64756415 64946425 6464 69

ji

To partition the array into two parts, we only need O(1)extra space.

Page 134: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

30/58

Quicksort Can Be Implemented as an “In-Place”

Sorting Algorithm

In-Place Sorting Algorithm: an algorithm that only uses“small” extra space.

1582 75 6938 94 25 76 92 3745 8564 2917 1764826437 64756415 64946425 6464 69

ji

To partition the array into two parts, we only need O(1)extra space.

Page 135: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

31/58

Outline

1 Approximation Algorithms

2 Approximation Algorithms for Traveling Salesman Problem

3 2-Approximation Algorithm for Vertex Cover

4 78-Approximation Algorithm for Max 3-SAT

5 Randomized QuicksortRecap of QuicksortRandomized Quicksort Algorithm

6 2-Approximation Algorithm for (Weighted) Vertex Cover ViaLinear Programming

Linear Programming2-Approximation for Weighted Vertex Cover

Page 136: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

32/58

Randomized Quicksort Algorithm

quicksort(A, n)

1 if n ≤ 1 then return A

2 x← a random element of A (x is called a pivot)

3 AL ← elements in A that are less than x \\ Divide

4 AR ← elements in A that are greater than x \\ Divide

5 BL ← quicksort(AL, AL.size) \\ Conquer

6 BR ← quicksort(AR, AR.size) \\ Conquer

7 t← number of times x appear A

8 return the array obtained by concatenating BL, the arraycontaining t copies of x, and BR

Page 137: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

33/58

Variant of Randomized Quicksort Algorithm

quicksort(A, n)

1 if n ≤ 1 then return A

2 repeat

3 x← a random element of A (x is called a pivot)

4 AL ← elements in A that are less than x \\ Divide

5 AR ← elements in A that are greater than x \\ Divide

6 unitl AL.size ≤ 3n/4 and AR.size ≤ 3n/4

7 BL ← quicksort(AL, AL.size) \\ Conquer

8 BR ← quicksort(AR, AR.size) \\ Conquer

9 t← number of times x appear A

10 return the array obtained by concatenating BL, the arraycontaining t copies of x, and BR

Page 138: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

34/58

Analysis of Variant

3 x← a random element of A

4 AL ← elements in A that are less than x

5 AR ← elements in A that are greater than x

Q: What is the probability that AL.size ≤ 3n/4 andAR.size ≤ 3n/4?

A: At least 1/2

Page 139: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

34/58

Analysis of Variant

3 x← a random element of A

4 AL ← elements in A that are less than x

5 AR ← elements in A that are greater than x

Q: What is the probability that AL.size ≤ 3n/4 andAR.size ≤ 3n/4?

A: At least 1/2

Page 140: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

35/58

Analysis of Variant

2 repeat

3 x← a random element of A

4 AL ← elements in A that are less than x

5 AR ← elements in A that are greater than x

6 unitl AL.size ≤ 3n/4 and AR.size ≤ 3n/4

Q: What is the expected number of iterations the aboveprocedure takes?

A: At most 2

Page 141: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

35/58

Analysis of Variant

2 repeat

3 x← a random element of A

4 AL ← elements in A that are less than x

5 AR ← elements in A that are greater than x

6 unitl AL.size ≤ 3n/4 and AR.size ≤ 3n/4

Q: What is the expected number of iterations the aboveprocedure takes?

A: At most 2

Page 142: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

36/58

Suppose an experiment succeeds with probability p ∈ (0, 1],independent of all previous experiments.

1 repeat

2 run an experiment

3 until the experiment succeeds

Lemma The expected number of experiments we run in theabove procedure is 1/p.

Page 143: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

37/58

Fact For q ∈ (0, 1), we have∑∞

i=0 qi = 1

1−q .

Page 144: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

38/58

Lemma The expected number of experiments we run in theabove procedure is 1/p.

Proof

Expectation = p+ (1− p)p× 2 + (1− p)2p× 3 + (1− p)3p× 4

+ · · ·

= p∞∑i=1

(1− p)i−1i = p∞∑j=1

∞∑i=j

(1− p)i−1

= p∞∑j=1

(1− p)j−1 1

1− (1− p) =∞∑j=1

(1− p)j−1

= (1− p)0 1

1− (1− p) = 1/p

Page 145: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

39/58

Variant Randomized Quicksort Algorithm

quicksort(A, n)

1 if n ≤ 1 then return A

2 repeat

3 x← a random element of A (x is called a pivot)

4 AL ← elements in A that are less than x \\ Divide

5 AR ← elements in A that are greater than x \\ Divide

6 unitl AL.size ≤ 3n/4 and AR.size ≤ 3n/4

7 BL ← quicksort(AL, AL.size) \\ Conquer

8 BR ← quicksort(AR, AR.size) \\ Conquer

9 t← number of times x appear A

10 return the array obtained by concatenating BL, the arraycontaining t copies of x, and BR

Page 146: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

40/58

Analysis of Variant

Divide and Combine: takes O(n) time

Conquer: break an array of size n into two arrays, each hassize at most 3n/4. Recursively sort the 2 sub-arrays.

n≤ 3n/4

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

O(n)

O(n)

O(n)

O(n)

≤ 9n/16

≤ 27n/64

Number of levels ≤ lg4/3 n = O(lg n)

Page 147: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

41/58

Randomized Quicksort Algorithm

quicksort(A, n)

1 if n ≤ 1 then return A

2 x← a random element of A (x is called a pivot)

3 AL ← elements in A that are less than x \\ Divide

4 AR ← elements in A that are greater than x \\ Divide

5 BL ← quicksort(AL, AL.size) \\ Conquer

6 BR ← quicksort(AR, AR.size) \\ Conquer

7 t← number of times x appear A

8 return the array obtained by concatenating BL, the arraycontaining t copies of x, and BR

Intuition: the quicksort algorithm should be better than thevariant.

Page 148: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

42/58

Analysis of Randomized Quicksort Algorithm

T (n): an upper bound on the expected running time of therandomized quicksort algorithm on n elements

Assuming we choose the element of rank i as the pivot.

The left sub-instance has size at most i− 1

The right sub-instance has size at most n− iThus, the expected running time in this case is(T (i− 1) + T (n− i)

)+O(n)

Overall, we have

T (n) =1

n

n∑i=1

(T (i− 1) + T (n− i)

)+O(n)

=2

n

n−1∑i=0

T (i) +O(n)

Can prove T (n) ≤ c(n lg n) for some constant c by reduction

Page 149: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

42/58

Analysis of Randomized Quicksort Algorithm

T (n): an upper bound on the expected running time of therandomized quicksort algorithm on n elements

Assuming we choose the element of rank i as the pivot.

The left sub-instance has size at most i− 1

The right sub-instance has size at most n− iThus, the expected running time in this case is(T (i− 1) + T (n− i)

)+O(n)

Overall, we have

T (n) =1

n

n∑i=1

(T (i− 1) + T (n− i)

)+O(n)

=2

n

n−1∑i=0

T (i) +O(n)

Can prove T (n) ≤ c(n lg n) for some constant c by reduction

Page 150: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

42/58

Analysis of Randomized Quicksort Algorithm

T (n): an upper bound on the expected running time of therandomized quicksort algorithm on n elements

Assuming we choose the element of rank i as the pivot.

The left sub-instance has size at most i− 1

The right sub-instance has size at most n− iThus, the expected running time in this case is(T (i− 1) + T (n− i)

)+O(n)

Overall, we have

T (n) =1

n

n∑i=1

(T (i− 1) + T (n− i)

)+O(n)

=2

n

n−1∑i=0

T (i) +O(n)

Can prove T (n) ≤ c(n lg n) for some constant c by reduction

Page 151: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

42/58

Analysis of Randomized Quicksort Algorithm

T (n): an upper bound on the expected running time of therandomized quicksort algorithm on n elements

Assuming we choose the element of rank i as the pivot.

The left sub-instance has size at most i− 1

The right sub-instance has size at most n− i

Thus, the expected running time in this case is(T (i− 1) + T (n− i)

)+O(n)

Overall, we have

T (n) =1

n

n∑i=1

(T (i− 1) + T (n− i)

)+O(n)

=2

n

n−1∑i=0

T (i) +O(n)

Can prove T (n) ≤ c(n lg n) for some constant c by reduction

Page 152: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

42/58

Analysis of Randomized Quicksort Algorithm

T (n): an upper bound on the expected running time of therandomized quicksort algorithm on n elements

Assuming we choose the element of rank i as the pivot.

The left sub-instance has size at most i− 1

The right sub-instance has size at most n− iThus, the expected running time in this case is(T (i− 1) + T (n− i)

)+O(n)

Overall, we have

T (n) =1

n

n∑i=1

(T (i− 1) + T (n− i)

)+O(n)

=2

n

n−1∑i=0

T (i) +O(n)

Can prove T (n) ≤ c(n lg n) for some constant c by reduction

Page 153: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

42/58

Analysis of Randomized Quicksort Algorithm

T (n): an upper bound on the expected running time of therandomized quicksort algorithm on n elements

Assuming we choose the element of rank i as the pivot.

The left sub-instance has size at most i− 1

The right sub-instance has size at most n− iThus, the expected running time in this case is(T (i− 1) + T (n− i)

)+O(n)

Overall, we have

T (n) =1

n

n∑i=1

(T (i− 1) + T (n− i)

)+O(n)

=2

n

n−1∑i=0

T (i) +O(n)

Can prove T (n) ≤ c(n lg n) for some constant c by reduction

Page 154: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

42/58

Analysis of Randomized Quicksort Algorithm

T (n): an upper bound on the expected running time of therandomized quicksort algorithm on n elements

Assuming we choose the element of rank i as the pivot.

The left sub-instance has size at most i− 1

The right sub-instance has size at most n− iThus, the expected running time in this case is(T (i− 1) + T (n− i)

)+O(n)

Overall, we have

T (n) =1

n

n∑i=1

(T (i− 1) + T (n− i)

)+O(n)

=2

n

n−1∑i=0

T (i) +O(n)

Can prove T (n) ≤ c(n lg n) for some constant c by reduction

Page 155: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

42/58

Analysis of Randomized Quicksort Algorithm

T (n): an upper bound on the expected running time of therandomized quicksort algorithm on n elements

Assuming we choose the element of rank i as the pivot.

The left sub-instance has size at most i− 1

The right sub-instance has size at most n− iThus, the expected running time in this case is(T (i− 1) + T (n− i)

)+O(n)

Overall, we have

T (n) =1

n

n∑i=1

(T (i− 1) + T (n− i)

)+O(n)

=2

n

n−1∑i=0

T (i) +O(n)

Can prove T (n) ≤ c(n lg n) for some constant c by reduction

Page 156: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

43/58

Analysis of Randomized Quicksort Algorithm

The induction step of the proof:

T (n) ≤ 2

n

n−1∑i=0

T (i) + c′n ≤ 2

n

n−1∑i=0

ci lg i+ c′n

≤ 2c

n

bn/2c−1∑i=0

i lgn

2+

n−1∑i=bn/2c

i lg n

+ c′n

≤ 2c

n

(n2

8lgn

2+

3n2

8lg n

)+ c′n

= c

(n

4lg n− n

4+

3n

4lg n

)+ c′n

= cn lg n− cn

4+ c′n ≤ cn lg n if c ≥ 4c′

Page 157: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

44/58

Exercise: Coupon Collector

Coupon Collector

Each box of cereal contains a coupon. There are n differenttypes of coupons. Assuming all boxes are equally likely to containeach coupon, in expectation, how many boxes before you have allcoupon types?

Break into n stages 1, 2, 3, · · · , nStage i terminates when we have collected i coupon types

Xi: number of coupons collected in stage i

X =∑n

i=1Xi: total number of coupons collected

Page 158: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

45/58

Exercise: Coupon Collector

Xi: number of coupons collected in stage i

X =∑n

i=1Xi: total number of coupons collected

In stage i: with probability n−(i−1)n

, a random coupon hastype different from the i− 1 types already seen

Thus, E[Xi] = nn−(i−1)

.

By linearity of expectation:

E[X] =n∑

i=1

n

n− (i− 1)=

n∑i=1

n

i= nH(n),

where H(n) = 1 + 12

+ 13

+ · · ·+ 1n

= Θ(lg n) is called then-th Harmonic number.

E[X] = Θ(n lg n).

Page 159: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

46/58

Outline

1 Approximation Algorithms

2 Approximation Algorithms for Traveling Salesman Problem

3 2-Approximation Algorithm for Vertex Cover

4 78-Approximation Algorithm for Max 3-SAT

5 Randomized QuicksortRecap of QuicksortRandomized Quicksort Algorithm

6 2-Approximation Algorithm for (Weighted) Vertex Cover ViaLinear Programming

Linear Programming2-Approximation for Weighted Vertex Cover

Page 160: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

47/58

Outline

1 Approximation Algorithms

2 Approximation Algorithms for Traveling Salesman Problem

3 2-Approximation Algorithm for Vertex Cover

4 78-Approximation Algorithm for Max 3-SAT

5 Randomized QuicksortRecap of QuicksortRandomized Quicksort Algorithm

6 2-Approximation Algorithm for (Weighted) Vertex Cover ViaLinear Programming

Linear Programming2-Approximation for Weighted Vertex Cover

Page 161: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

48/58

Example of Linear Programming

min 4x1 + 5x2 s.t.

2x1 + x2 ≥ 6

x1 + 2x2 ≥ 4

x1, x2 ≥ 0

optimum point: x1 = 83, x2 = 2

3

value = 4× 83

+ 5× 23

= 14

0 1 2 3 4

1

2

3

4

5

6

x1

x2

7

8

5

Feasible Region

Page 162: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

48/58

Example of Linear Programming

min 4x1 + 5x2 s.t.

2x1 + x2 ≥ 6

x1 + 2x2 ≥ 4

x1, x2 ≥ 0

optimum point: x1 = 83, x2 = 2

3

value = 4× 83

+ 5× 23

= 14

0 1 2 3 4

1

2

3

4

5

6

x1

x2

7

8

5

Feasible Region

Page 163: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

48/58

Example of Linear Programming

min 4x1 + 5x2 s.t.

2x1 + x2 ≥ 6

x1 + 2x2 ≥ 4

x1, x2 ≥ 0

optimum point: x1 = 83, x2 = 2

3

value = 4× 83

+ 5× 23

= 14

0 1 2 3 4

1

2

3

4

5

6

x1

x2

7

8

5

Feasible Region

Page 164: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

48/58

Example of Linear Programming

min 4x1 + 5x2 s.t.

2x1 + x2 ≥ 6

x1 + 2x2 ≥ 4

x1, x2 ≥ 0

optimum point: x1 = 83, x2 = 2

3

value = 4× 83

+ 5× 23

= 14

0 1 2 3 4

1

2

3

4

5

6

x1

x2

7

8

5

Feasible Region

Page 165: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

48/58

Example of Linear Programming

min 4x1 + 5x2 s.t.

2x1 + x2 ≥ 6

x1 + 2x2 ≥ 4

x1, x2 ≥ 0

optimum point: x1 = 83, x2 = 2

3

value = 4× 83

+ 5× 23

= 14

0 1 2 3 4

1

2

3

4

5

6

x1

x2

7

8

5

Feasible Region

Page 166: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

48/58

Example of Linear Programming

min 4x1 + 5x2 s.t.

2x1 + x2 ≥ 6

x1 + 2x2 ≥ 4

x1, x2 ≥ 0

optimum point: x1 = 83, x2 = 2

3

value = 4× 83

+ 5× 23

= 14

0 1 2 3 4

1

2

3

4

5

6

x1

x2

7

8

5

Feasible Region

Page 167: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

48/58

Example of Linear Programming

min 4x1 + 5x2 s.t.

2x1 + x2 ≥ 6

x1 + 2x2 ≥ 4

x1, x2 ≥ 0

optimum point: x1 = 83, x2 = 2

3

value = 4× 83

+ 5× 23

= 140 1 2 3 4

1

2

3

4

5

6

x1

x2

7

8

5

Feasible Region

Page 168: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

49/58

Standard Form of Linear Programming

min c1x1 + c2x2 + · · ·+ cnxn s.t.∑A1,1x1 + A1,2x2 + · · ·+ A1,nxn ≥ b1∑A2,1x1 + A2,2x2 + · · ·+ A2,nxn ≥ b2

......

......∑

Am,1x1 + Am,2x2 + · · ·+ Am,nxn ≥ bm

x1, x2, · · · , xn ≥ 0

Page 169: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

50/58

Standard Form of Linear Programming

Let x =

x1

x2...xn

, c =

c1

c2...cn

,

A =

A1,1 A1,2 · · · A1,n

A2,1 A2,2 · · · A2,n...

......

...Am,1 Am,2 · · · Am,n

, b =

b1

b2...bm

.

Then, LP becomes min cTx s.t.

Ax ≥ b

x ≥ 0

≥ means coordinate-wise greater than or equal to

Page 170: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

51/58

Linear programmings can be solved in polynomial time

Algorithms for Solving LPs

Simplex method: exponential time in theory, but works wellin practice

Ellipsoid method: polynomial time in theory, but slow inpractice

Internal point method: polynomial time in theory, works wellin practice

Page 171: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

52/58

Outline

1 Approximation Algorithms

2 Approximation Algorithms for Traveling Salesman Problem

3 2-Approximation Algorithm for Vertex Cover

4 78-Approximation Algorithm for Max 3-SAT

5 Randomized QuicksortRecap of QuicksortRandomized Quicksort Algorithm

6 2-Approximation Algorithm for (Weighted) Vertex Cover ViaLinear Programming

Linear Programming2-Approximation for Weighted Vertex Cover

Page 172: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

53/58

Def. Given a graph G = (V,E), a vertex cover of G is a subsetS ⊆ V such that for every (u, v) ∈ E then u ∈ S or v ∈ S .

Weighted Vertex-Cover Problem

Input: G = (V,E) with vertex weights wvv∈VOutput: a vertex cover S with minimum

∑v∈S wv

Page 173: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

53/58

Def. Given a graph G = (V,E), a vertex cover of G is a subsetS ⊆ V such that for every (u, v) ∈ E then u ∈ S or v ∈ S .

Weighted Vertex-Cover Problem

Input: G = (V,E) with vertex weights wvv∈VOutput: a vertex cover S with minimum

∑v∈S wv

Page 174: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

53/58

Def. Given a graph G = (V,E), a vertex cover of G is a subsetS ⊆ V such that for every (u, v) ∈ E then u ∈ S or v ∈ S .

Weighted Vertex-Cover Problem

Input: G = (V,E) with vertex weights wvv∈VOutput: a vertex cover S with minimum

∑v∈S wv

Page 175: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

54/58

Integer Programming for Weighted Vertex Cover

For every v ∈ V , let xv ∈ 0, 1 indicate whether we select vin the vertex cover S

The integer programming for weighted vertex cover:

(IPWVC) min∑v∈V

wvxv s.t.

xu + xv ≥ 1 ∀(u, v) ∈ Exv ∈ 0, 1 ∀v ∈ V

(IPWVC) ⇔ weighted vertex cover

Thus it is NP-hard to solve integer programmings in general

Page 176: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

55/58

Integer programming for WVC:

(IPWVC) min∑v∈V

wvxv s.t.

xu + xv ≥ 1 ∀(u, v) ∈ Exv ∈ 0, 1 ∀v ∈ V

Linear programming relaxation for WVC:

(LPWVC) min∑v∈V

wvxv s.t.

xu + xv ≥ 1 ∀(u, v) ∈ Exv ∈ [0, 1] ∀v ∈ V

let IP = value of (IPWVC), LP = value of (LPWVC)

Then, LP ≤ IP

Page 177: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

55/58

Integer programming for WVC:

(IPWVC) min∑v∈V

wvxv s.t.

xu + xv ≥ 1 ∀(u, v) ∈ Exv ∈ 0, 1 ∀v ∈ V

Linear programming relaxation for WVC:

(LPWVC) min∑v∈V

wvxv s.t.

xu + xv ≥ 1 ∀(u, v) ∈ Exv ∈ [0, 1] ∀v ∈ V

let IP = value of (IPWVC), LP = value of (LPWVC)

Then, LP ≤ IP

Page 178: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

55/58

Integer programming for WVC:

(IPWVC) min∑v∈V

wvxv s.t.

xu + xv ≥ 1 ∀(u, v) ∈ Exv ∈ 0, 1 ∀v ∈ V

Linear programming relaxation for WVC:

(LPWVC) min∑v∈V

wvxv s.t.

xu + xv ≥ 1 ∀(u, v) ∈ Exv ∈ [0, 1] ∀v ∈ V

let IP = value of (IPWVC), LP = value of (LPWVC)

Then, LP ≤ IP

Page 179: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

55/58

Integer programming for WVC:

(IPWVC) min∑v∈V

wvxv s.t.

xu + xv ≥ 1 ∀(u, v) ∈ Exv ∈ 0, 1 ∀v ∈ V

Linear programming relaxation for WVC:

(LPWVC) min∑v∈V

wvxv s.t.

xu + xv ≥ 1 ∀(u, v) ∈ Exv ∈ [0, 1] ∀v ∈ V

let IP = value of (IPWVC), LP = value of (LPWVC)

Then, LP ≤ IP

Page 180: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

56/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2

Thus, LP =∑

u∈V wux∗u ≤ IP

3

Let S = u ∈ V : xu ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Proof.

Consider any edge (u, v) ∈ E: we have x∗u + x∗v ≥ 1

Thus, either x∗u ≥ 1/2 or x∗v ≥ 1/2

Thus, either u ∈ S or v ∈ S.

Page 181: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

56/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3

Let S = u ∈ V : xu ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Proof.

Consider any edge (u, v) ∈ E: we have x∗u + x∗v ≥ 1

Thus, either x∗u ≥ 1/2 or x∗v ≥ 1/2

Thus, either u ∈ S or v ∈ S.

Page 182: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

56/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : xu ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Proof.

Consider any edge (u, v) ∈ E: we have x∗u + x∗v ≥ 1

Thus, either x∗u ≥ 1/2 or x∗v ≥ 1/2

Thus, either u ∈ S or v ∈ S.

Page 183: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

56/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : xu ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Proof.

Consider any edge (u, v) ∈ E: we have x∗u + x∗v ≥ 1

Thus, either x∗u ≥ 1/2 or x∗v ≥ 1/2

Thus, either u ∈ S or v ∈ S.

Page 184: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

56/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : xu ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Proof.

Consider any edge (u, v) ∈ E: we have x∗u + x∗v ≥ 1

Thus, either x∗u ≥ 1/2 or x∗v ≥ 1/2

Thus, either u ∈ S or v ∈ S.

Page 185: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

56/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : xu ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Proof.

Consider any edge (u, v) ∈ E: we have x∗u + x∗v ≥ 1

Thus, either x∗u ≥ 1/2 or x∗v ≥ 1/2

Thus, either u ∈ S or v ∈ S.

Page 186: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

56/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : xu ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Proof.

Consider any edge (u, v) ∈ E: we have x∗u + x∗v ≥ 1

Thus, either x∗u ≥ 1/2 or x∗v ≥ 1/2

Thus, either u ∈ S or v ∈ S.

Page 187: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

56/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : xu ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Proof.

Consider any edge (u, v) ∈ E: we have x∗u + x∗v ≥ 1

Thus, either x∗u ≥ 1/2 or x∗v ≥ 1/2

Thus, either u ∈ S or v ∈ S.

Page 188: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

57/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : xu ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Lemma cost(S) :=∑

u∈S wu ≤ 2 · LP.

Proof.

cost(S) =∑u∈S

wu ≤∑u∈S

wu · 2x∗u = 2∑u∈S

wu · x∗u

≤ 2∑u∈V

wu · x∗u = 2 · LP.

Page 189: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

57/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : xu ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Lemma cost(S) :=∑

u∈S wu ≤ 2 · LP.

Proof.

cost(S) =∑u∈S

wu ≤∑u∈S

wu · 2x∗u = 2∑u∈S

wu · x∗u

≤ 2∑u∈V

wu · x∗u = 2 · LP.

Page 190: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

57/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : xu ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Lemma cost(S) :=∑

u∈S wu ≤ 2 · LP.

Proof.

cost(S) =∑u∈S

wu ≤∑u∈S

wu · 2x∗u = 2∑u∈S

wu · x∗u

≤ 2∑u∈V

wu · x∗u = 2 · LP.

Page 191: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

58/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : x∗u ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Lemma cost(S) :=∑

u∈S wu ≤ 2 · LP.

Theorem Algorithm is a 2-approximation algorithm for WVC.

Proof.

cost(S) ≤ 2 · LP ≤ 2 · IP = 2 · cost(best vertex cover).

Page 192: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

58/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : x∗u ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Lemma cost(S) :=∑

u∈S wu ≤ 2 · LP.

Theorem Algorithm is a 2-approximation algorithm for WVC.

Proof.

cost(S) ≤ 2 · LP ≤ 2 · IP = 2 · cost(best vertex cover).

Page 193: Approximation and Randomized Algorithmsshil/courses/CSE531-Fall2016/Slides/Approximation.pdf · 5 Randomized Quicksort Recap of Quicksort Randomized Quicksort Algorithm 6 2-Approximation

58/58

Algorithm for Weighted Vertex Cover

Algorithm for Weighted Vertex Cover

1 Solving (LPWVC) to obtain a solution x∗uu∈V2 Thus, LP =

∑u∈V wux

∗u ≤ IP

3 Let S = u ∈ V : x∗u ≥ 1/2 and output S

Lemma S is a vertex cover of G.

Lemma cost(S) :=∑

u∈S wu ≤ 2 · LP.

Theorem Algorithm is a 2-approximation algorithm for WVC.

Proof.

cost(S) ≤ 2 · LP ≤ 2 · IP = 2 · cost(best vertex cover).