Algorithms and Complexity Lecture 7 Dynamic Programming and

  • Slides: 43
Download presentation
Algorithms and Complexity Lecture 7 Dynamic Programming and Inclusion Exclusion 1

Algorithms and Complexity Lecture 7 Dynamic Programming and Inclusion Exclusion 1

Overview of Today • Dynamic Programming – Subset Sum / Knapsack apx – Coloring

Overview of Today • Dynamic Programming – Subset Sum / Knapsack apx – Coloring – Traveling Salesman Problem – Steiner Tree (if time) – Weighted Independent Set on trees (if time) • Inclusion Exclusion – Hamiltonian Cycle – k-coloring 2

Dynamic Programming (DP) • The method works with a big table of data that

Dynamic Programming (DP) • The method works with a big table of data that has to be stored in memory. • A relatively easy procedure computes new table entries using already computed table entries. • This easy procedure is often so easy that we just write it down as a single formula, obtaining a recurrence. • Other interpretation: – cleverly define subproblems, – solve easier subproblems first; store solutions – use solutions of easier subproblem to solve harder ones – the original problem also is a subproblem 3

Subset Sum • A[0, 0], A[2, 0], A[3, 5], A[6, 12], A[4, 20], A[12,

Subset Sum • A[0, 0], A[2, 0], A[3, 5], A[6, 12], A[4, 20], A[12, 50]? 4

0 1 . . . n 0 1 2 3 4 5 6 7

0 1 . . . n 0 1 2 3 4 5 6 7 8 9 10. . . t ? 5

0 1 . . . n 0 1 2 3 4 5 6 7

0 1 . . . n 0 1 2 3 4 5 6 7 8 9 10. . . t ? 6

0 1 . . . n 0 1 2 3 4 5 6 7

0 1 . . . n 0 1 2 3 4 5 6 7 8 9 10. . . t ? 7

0 1 . . . n 0 1 2 3 4 5 6 7

0 1 . . . n 0 1 2 3 4 5 6 7 8 9 10. . . t ? 8

0 1 . . . n 0 1 2 3 4 5 6 7

0 1 . . . n 0 1 2 3 4 5 6 7 8 9 10. . . t ? 9

0 1 . . . n 0 1 2 3 4 5 6 7

0 1 . . . n 0 1 2 3 4 5 6 7 8 9 10. . . t ? 10

0 1 . . . n 0 1 2 3 4 5 6 7

0 1 . . . n 0 1 2 3 4 5 6 7 8 9 10. . . t ? 11

0 1 . . . n 0 1 2 3 4 5 6 7

0 1 . . . n 0 1 2 3 4 5 6 7 8 9 10. . . t ? 12

0 1 . . . n 0 1 2 3 4 5 6 7

0 1 . . . n 0 1 2 3 4 5 6 7 8 9 10. . . t ? 13

0 1 . . . n 0 1 2 3 4 5 6 7

0 1 . . . n 0 1 2 3 4 5 6 7 8 9 10. . . t ? 14

0 1 . . . n 0 1 2 3 4 5 6 7

0 1 . . . n 0 1 2 3 4 5 6 7 8 9 10. . . t ? 15

Knapsack • 16

Knapsack • 16

Approximation scheme for Knapsack • 17

Approximation scheme for Knapsack • 17

Approximation for Knapsack • 18

Approximation for Knapsack • 18

Approximation for Knapsack 19

Approximation for Knapsack 19

20

20

21

21

Traveling Salesman Problem • 1 c 2 3 2 a b e 2 2

Traveling Salesman Problem • 1 c 2 3 2 a b e 2 2 1 d 4 2 3 f 2 22

Traveling Salesman Problem • 1 c 2 3 2 a b e 2 2

Traveling Salesman Problem • 1 c 2 3 2 a b e 2 2 1 d 4 2 3 f 2 23

Traveling Salesman Problem • 1 c 2 3 2 a b e 2 2

Traveling Salesman Problem • 1 c 2 3 2 a b e 2 2 1 d 4 2 3 f 2 24

Traveling Salesman Problem • 1 c 2 3 2 a b e 2 2

Traveling Salesman Problem • 1 c 2 3 2 a b e 2 2 1 d 4 2 3 f 2 25

Traveling Salesman Problem • X t’ s t’ t’ t 26

Traveling Salesman Problem • X t’ s t’ t’ t 26

Traveling Salesman Problem • 27

Traveling Salesman Problem • 27

28

28

29

29

30

30

g l d i f a b e j c h k 31

g l d i f a b e j c h k 31

 • Intuitively: r’ r 32

• Intuitively: r’ r 32

33

33

34

34

Inclusion Exclusion • 35

Inclusion Exclusion • 35

36

36

Inclusion Exclusion Formula • 37

Inclusion Exclusion Formula • 37

Inclusion Exclusion Formula • 38

Inclusion Exclusion Formula • 38

 • • Hard to compute…. 41

• • Hard to compute…. 41

Weighted Independent Set in Trees • 43

Weighted Independent Set in Trees • 43