dynamicpro - Dynamic Programming One technique that...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Dynamic Programming One technique that attempts to solve problems by dividing them into subproblems is called dynamic programming. It uses a “bottom-up” approach in that the subproblems are arranged and solved in a systematic fashion, which leads to a solution to the original problem. This bottom-up approach implementation is more efficient than a “top-down” counterpart mainly because duplicated computation of the same problems is eliminated. This technique is typically applied to solving optimization problems, although it is not limited to only optimization problems. Dynamic programming typically involves two steps: (1) develop a recursive strategy for solving the problem; and (2) develop a “bottom-up” implementation without recursion.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example: Compute the binomial coefficients C ( n , k ) defined by the following recursive formula: The following “call tree” demonstrates repeated (duplicated) computations in a straightforward recursive implementation: < < - - + - = = = otherwise. , 0 ; 0 if ), 1 , 1 ( ) , 1 ( ; or 0 if , 1 ) , ( n k k n C k n C n k k k n C C (5,3) C (4,3) C (4,2) C (3,3) C (3,2) C (3,1) C (2,2) C (2,1) C (2,0) C (1,1) C (1,0) Notice repeated calls to C (3,2) and to C (2,1). In general, the number of calls for computing C ( n , k ) is 2 C ( n , k ) – 1, which can be exponentially large.
Background image of page 2
A more efficient way to compute C ( n , k ) is to organize the computation steps of C ( i , j ), 0 i n and 0 j k , in a tabular format and compute the values by rows (the i dimension) and within the same row by columns (the j dimension): 0 1 2 . . . k 0 1 2 n i– dimension j –dimension 1 1 1 1 2 1 C ( n –1, k –1) C ( n –1, k ) C ( n , k ) add C ( n –1, k –1) and C ( n –1, k ) t o compute C ( n , k )
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
It can be seen that the number of steps (add operation) is O( nk ) in computing C ( n , k ), using O( nk ) amount of space (I.e., the table). In fact, since only the previous row of values are needed in computing the next row of the table, space for only two rows is needed reducing the space complexity to O( k ). The following table demonstrates the computation steps for calculating C (5,3): 0 1 2 3 0 1 2 3 4 5 1 1 1 1 1 1 1 2 3 4 5 1 3 6 10 10 1 4 = C (5,3) Note that this table shows Pascal’s triangle in computing the binomial coefficients.
Background image of page 4
Example: Solve the make-change problem using dynamic programming. Suppose there are n types of coin denominations, d 1 , d 2 , …, and d n . (We may assume one of them is penny.) There are an infinite supply of coins of each type. To make change for an arbitrary amount j using the minimum number of coins, we first apply the following recursive idea: If there are only pennies, the problem is simple: simply use j pennies to make change for the total amount j .
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/13/2011.

Page1 / 17

dynamicpro - Dynamic Programming One technique that...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online