CMPU 102 - Assignment 8 Due: by 11:59 PM on Thursday, November 10th

$Revision: 1.3 $

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 into your Eclipse workspace.  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.


Run the main method of the TestDriver class by right-clicking on "" 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.


From a terminal window:

cd eclipse-workspace
submit102 nchoosek