CS 201 - Lab 9

Binomial Coefficient

The binomial cooefficient C(n,k), often written "n choose k", is the number of ways to pick a subset of k elements from a collection of n elements.  It may be defined recursively as follows:

C(n,0) = 1
C(n,n) = 1
C(n,k) = C(n-1,k) + C(n-1, k-1)

Getting Started

Import the file lab9.zip into your Eclipse workspace (File->Import...->General->Existing Projects into Workspace->Archive File).  You should see a project called lab9 in the Package Explorer.

Your Task

You will implement the compute method of the classes NaiveRecursive and DynamicProgramming.  As the names suggest, NaiveRecursive should be a literal recursive implementation of the binomial coefficient function, and DynamicProgramming should implement the binomial coefficient function using dynamic programming to avoid repeatedly solving identical subproblems.

Because the binomial coefficient function takes two parameters, n and k, you will probably want your memoization table to be a two-dimensional array.

Testing

Run the main method of the TestDriver class by right-clicking on "TestDriver.java" and choosing "Run As->Java Application".  The test driver solves C(n,k) for all values of k 0..n, for n=25, and measures the number of milliseconds needed to solve each problem.  While the naive recursive implementation will take an appreciable amount of time, the dynamic programming implementation should execute fairly quickly.