Review 6: Dynamic programming

printable version

R6: [1] [2] [3] [4] [5] [6] [7]

Problem R6.1

Consider the following recursive algorithm.

public static int f(int nint r) {
    if(r == 0 || r >= nreturn 1;
    else                 return f(n - 1r - 1) + f(n - 1r);
}

Using dynamic programming, convert this into a method that takes O(n ⋅ r) time.