15
itu Independent Set True of False? Flow Network BLG 336E – Analysis of Algorithms II Practice Session 5 Atakan Aral Istanbul Technical University – Department of Computer Engineering 29.04.2014 Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II

Analysis of Algorithms II - PS5

Embed Size (px)

Citation preview

Page 1: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

BLG 336E – Analysis of Algorithms IIPractice Session 5

Atakan Aral

Istanbul Technical University – Department of Computer Engineering

29.04.2014

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 2: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Outline

1 Independent Set

2 True of False?

3 Flow Network

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 3: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Problem

Find an independent set in a path G whose total weight isas large as possible.

Independent Set

Subset of nodes such that no two of them are adjacent(connected by an edge).

6 3

8

6

1

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 4: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Solution

Attempt 1: Odds vs. evens

1 + 6 + 6 vs. 8 + 3Yields 13 which is sub-optimal.

6 3

8

6

1

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 5: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Solution

Attempt 2: Heaviest-first

Take 8, remove first 3 nodes then take 6.Yields 14 which is optimal.

6 3

8

6

1

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 6: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Solution

Attempt 2: Heaviest-first

What about now?Yields 13 which is sub-optimal.

6 3

7

4

5

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 7: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Solution

Attempt 3: Dynamic Programming

Si : Independent set on v1, v2, ...vi

Xi : Weight of Si

X0 = 0X1 = w1

i > 1:1 vi does not belong to Si → Xi = Xi−12 vi belongs to Si → Xi = wi + Xi−2

So: Xi = max(Xi−1,wi + Xi−2)

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 8: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Solution

Attempt 3: Dynamic Programming

6 3

8

6

1

X0 = 0 S = ()

X1 = 1 S = (v1)

X2 = max(X1,w2 + X0) = max(1,8 + 0) = 8 S = (v2)

X3 = max(X2,w3 + X1) = max(8,6 + 1) = 8 S = (v2)

X4 = max(X3,w4 + X2) = max(8,3 + 8) = 11 S = (v2, v4)

X5 = max(X4,w5 + X3) = max(11,6 + 8) = 14 S = (v2, v5)

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 9: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Problem

Let G be an arbitrary flow network, with a source s, a sinkt , and a positive integer capacity ce on every edge e;let (A,B) be a minimum s − t cut with respect to thesecapacities ce.Now suppose we add 1 to every capacity; then (A,B) isstill a minimum s − t cut with respect to these newcapacities ce + 1.

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 10: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Solution

False:

b w

a

t

1

s

31

1

1

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 11: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Problem

Consider the flow network below.An s − t flow is computed.

What is the value of the flow?

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 12: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Problem

Consider the flow network below.An s − t flow is computed.

Is this a maximum s − t flow?

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 13: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Problem

Consider the flow network below.An s − t flow is computed.

Find the maximum s − t flow.

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 14: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Solution

Value is 18.We need to draw the residual graph to see if it is themaximum flow.

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II

Page 15: Analysis of Algorithms II - PS5

itu

Independent Set True of False? Flow Network

Solution

It is not the maximum flow.An augmenting path with a value of 3 can be found.Since no more augmenting paths are available themaximum flow is 18 + 3 = 21.

Atakan Aral Istanbul Technical University – Department of Computer Engineering

BLG 336E – Analysis of Algorithms II