Csci 6212 design and analysis of algorithms dynamic programming
This presentation is the property of its rightful owner.
Sponsored Links
1 / 15

CSCI 6212 Design and Analysis of Algorithms Dynamic Programming PowerPoint PPT Presentation


  • 154 Views
  • Uploaded on
  • Presentation posted in: General

CSCI 6212 Design and Analysis of Algorithms Dynamic Programming. Dr. Juman Byun The George Washington University. Please drop this course if you have not taken the following prerequisite. Sometimes enthusiasm alone is not enough. CSci 1311: Discrete Structures I (3)

Download Presentation

CSCI 6212 Design and Analysis of Algorithms Dynamic Programming

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Csci 6212 design and analysis of algorithms dynamic programming

CSCI 6212 Design and Analysis of AlgorithmsDynamic Programming

  • Dr. Juman Byun

  • The George Washington University

  • Please drop this course if you have not taken the following prerequisite. Sometimes enthusiasm alone is not enough.

  • CSci 1311: Discrete Structures I (3)

  • CSci 1112: Algorithms and Data Structures (3)


Example rod cutting

n=4

Example: Rod Cutting


Example rod cutting1

n=4

Example: Rod Cutting

Maximum Revenue, r4 ?


R n when n 4

rn when n=4 ?

$10

$9

$1

$8

$5

$5

$8

$1

$1

$1

$5

$1

$5

$1

$5

$1

$1

$1

$1

$1

$1


Notation

Notation

$10

$5

$5

4-inch

rod into 2 pieces

Decomposition:

4 = 2 + 2

Maximum Revenue:

r4 = $5 + $5


Notation1

Notation

rn

n-inch

rod into k pieces

Decomposition:

n = i1 + i2 + … + ik

Maximum Revenue:


General procedure to find optimal rod cutting

r1 + rn-1

Uncut Rod of length n

pn

General Procedure to Find Optimal Rod Cutting

Cut

Revenue

Pick the largest

r2 + rn-2

rn-2 + r2

rn-1 + r1


General procedure to find optimal rod cutting1

General Procedure to Find Optimal Rod Cutting


General procedure to find optimal rod cutting2

General Procedure to Find Optimal Rod Cutting


Recursive top down

Recursive Top-Down

  • Cut-Rod(p,n)

  • if n == 0

  • return 0

  • q = ∞

  • for i = 1 to n

  • q = max(q,p[i] + Cut-Rod(p, n - i ) )

  • return q


Vs divide and conquer

vs Divide-and-conquer

  • Similarity

  • to divides problems into subproblems

  • Difference

  • subproblems overlap


Can we do better

Can we do better ?


Momoized cut rod

Momoized-Cut-Rod

  • Memoized-Cut-Rod(p,n)

  • let r[0..n] be a new array

  • for i = 0 to n

  • r[i] = -∞

  • return Memoized-Cut-Rod-Aux(p,n,r)


Momoized cut rod aux

Momoized-Cut-Rod-Aux

  • Momoized-Cut-Rod-Aux(p,n)

  • if r[n] >= 0

  • return r[n]

  • if n == 0

  • q = 1

  • else q = -∞

  • for i = 1 to n

  • q = max(q,p[i]+Memoized-Cut-Rod-Aux(pn,n-i,r))

  • r[n] = q

  • return q


Bottom cut rod

Bottom-Cut-Rod

  • Bottom-Up-Cut-Rod(p,n)

  • let r[0..n] be a new array

  • r[0] = 0

  • for j = 1 to n

  • q = -∞

  • for i = 1 to j

  • q = max(q, p[i] + r[j-i])

  • r[j] = q

  • return r[n]


  • Login