Choose Function Given n and k with n greterthanequalto k greterthanequalto 0, we want to compute the choose function (n k) using the following recurrence: Base Cases: (n 0) = 1 and (n n) = 1, for n greterthanequalto 0 Recursive Case: (n k) = (n-1 k-1) + (n-1 k), for n > k > 0 Compute (4 3) using the above recurrence. Give pseudo-code for a bottom-up dynamic programming algorithm to compute (n k) using the above recurrence. Show the dynamic programming table your algorithm creates for (4 3).
Explanation / Answer
import java.util.Scanner; public class Knapsack_DP { static int max(int a, int b) { return (a > b)? a : b; } static int knapSack(int W, int wt[], int val[], int n) { int i, w; int [][]K = new int[n+1][W+1]; // Build table K[][] in bottom up manner for (i = 0; i