You are on page 1of 30

Dynamic Programming

Gefei Zhang
Celonis GmbH

2014-02-18

Gefei Zhang: Dynamic Programming

1/13

Gefei Zhang

Dipl.-Inform. and Dr.rer.nat. from LMU Software developer at Celonis GmbH

Gefei Zhang: Dynamic Programming

2/13

Celonis

The leading vendor for the analysis of operative process data created by IT systems [IBM] Interactive, process-based Business Intelligence Next level of transparency in enterprise process mining http://www.celonis.de

Gefei Zhang: Dynamic Programming

3/13

Celonis

Gefei Zhang: Dynamic Programming

4/13

Content

Dynamic Programming Warming up: Fibonacci Introduction: Maximum weighted independent set in a path Application: Knapsack

Gefei Zhang: Dynamic Programming

5/13

Fibonacci

f (n) = f (n 1) + f (n 2) simple, but horrible complexity

Gefei Zhang: Dynamic Programming

6/13

Fibonacci

f (n) = f (n 1) + f (n 2) simple, but horrible complexity better: bottom up a = 1; b = 1 for i in 3..n a, b = b, a+b return b

Gefei Zhang: Dynamic Programming

6/13

Maximum weighted independent set in a path

Example Index set I = 1, n Array arri > 0, i I

Gefei Zhang: Dynamic Programming

7/13

Maximum weighted independent set in a path

Example Index set I = 1, n Array arri > 0, i I Wanted: set S I , such that
x , y S , x > y , x y > 1

Gefei Zhang: Dynamic Programming

7/13

Maximum weighted independent set in a path

Example Index set I = 1, n Array arri > 0, i I Wanted: set S I , such that
x , y S , x > y , x y > 1 s S arrs max

Gefei Zhang: Dynamic Programming

7/13

Maximum weighted independent set in a path

Example Index set I = 1, n Array arri > 0, i I Wanted: set S I , such that
x , y S , x > y , x y > 1 s S arrs max

Gefei Zhang: Dynamic Programming

7/13

Maximum weighted independent set in a path


Sn optimal

Gefei Zhang: Dynamic Programming

8/13

Maximum weighted independent set in a path


Sn optimal n / Sn Sn = Sn1

Gefei Zhang: Dynamic Programming

8/13

Maximum weighted independent set in a path


Sn optimal n / Sn Sn = Sn1 n Sn Sn = Sn2 {n}

Gefei Zhang: Dynamic Programming

8/13

Maximum weighted independent set in a path


Sn optimal n / Sn Sn = Sn1 n Sn Sn = Sn2 {n} An the sum for optimal Sn

Gefei Zhang: Dynamic Programming

8/13

Maximum weighted independent set in a path


Sn optimal n / Sn Sn = Sn1 n Sn Sn = Sn2 {n} An the sum for optimal Sn n Sn An = An2 + arrn > An1

Gefei Zhang: Dynamic Programming

8/13

Maximum weighted independent set in a path


Sn optimal n / Sn Sn = Sn1 n Sn Sn = Sn2 {n} An the sum for optimal Sn n Sn An = An2 + arrn > An1 Recursion Ak = max (Ak 1 , Ak 2 + arrk )

Gefei Zhang: Dynamic Programming

8/13

Maximum weighted independent set in a path


Sn optimal n / Sn Sn = Sn1 n Sn Sn = Sn2 {n} An the sum for optimal Sn n Sn An = An2 + arrn > An1 Recursion Ak = max (Ak 1 , Ak 2 + arrk ) Bottom up for i in 3..n A[i] = max(A[i-1], A[i-2]+arr[i])

Gefei Zhang: Dynamic Programming

8/13

Maximum weighted independent set in a path


Sn optimal n / Sn Sn = Sn1 n Sn Sn = Sn2 {n} An the sum for optimal Sn n Sn An = An2 + arrn > An1 Recursion Ak = max (Ak 1 , Ak 2 + arrk ) Bottom up for i in 3..n A[i] = max(A[i-1], A[i-2]+arr[i]) Backtracking: from A to S Ai > Ai 1 i S and i 1 /S Ai < Ai 1 i /S
Gefei Zhang: Dynamic Programming 8/13

Knapsack Problem

Gefei Zhang: Dynamic Programming

9/13

Knapsack Problem

Index set I = 1, , n Given: {vi }, {wi }, i I , K > 0

Gefei Zhang: Dynamic Programming

9/13

Knapsack Problem

Index set I = 1, , n Given: {vi }, {wi }, i I , K > 0 Wanted: set S I , such that
i S

wi K

Gefei Zhang: Dynamic Programming

9/13

Knapsack Problem

Index set I = 1, , n Given: {vi }, {wi }, i I , K > 0 Wanted: set S I , such that
i S

wi K i S vi max

Gefei Zhang: Dynamic Programming

9/13

Knapsack Problem

Index set I = 1, , n Given: {vi }, {wi }, i I , K > 0 Wanted: set S I , such that
i S

wi K i S vi max

Gefei Zhang: Dynamic Programming

9/13

Knapsack Problem

Index set I = 1, , n Given: {vi }, {wi }, i I , K > 0 Wanted: set S I , such that
i S

wi K i S vi max

Example

Gefei Zhang: Dynamic Programming

9/13

Knapsack Problem

Sn,k optimal n / Sn,k Sn,k = Sn1,k n Sn,k Sn,k = Sn1,k wn {n} Vn,k the sum n Sn,k Vn1,k > Vn1,k wn + vn Recursion Vn,k = max (Vn1,k , Vn1,k wn + vn )

Gefei Zhang: Dynamic Programming

10/13

Knapsack Problem

Bottom up for i in 1..n for c in 1..K V[i,c] = max(V[i-1,c], V[i-1, c-w[i]] + v[i]) Backtracking Vn,k = Vn1,k i n /S

Gefei Zhang: Dynamic Programming

11/13

Summary

Dynamic Programming Recursion bottom up Evil mostly in nding recursion Applications in Graph Theory, Computer Linguistics, Bioinformatics, etc.

Gefei Zhang: Dynamic Programming

12/13

Summary

Dynamic Programming Recursion bottom up Evil mostly in nding recursion Applications in Graph Theory, Computer Linguistics, Bioinformatics, etc. Challenge Egg Dropping

Gefei Zhang: Dynamic Programming

12/13

Thanks

Danke

Gefei Zhang: Dynamic Programming

13/13

You might also like