29.01.2013 Views

Computing Binomial Coefficients using Dynamic Programming

Computing Binomial Coefficients using Dynamic Programming

Computing Binomial Coefficients using Dynamic Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Jackson State University<br />

Department of Computer Science<br />

CSC 323 Algorithm Design and Analysis<br />

Fall 2012<br />

Instructor: Dr. Natarajan Meghanathan<br />

<strong>Programming</strong> Assignment 8<br />

<strong>Computing</strong> <strong>Binomial</strong> <strong>Coefficients</strong> <strong>using</strong> <strong>Dynamic</strong> <strong>Programming</strong><br />

Assigned: October 17, 2012 Due: November 6, 2012, 11.30 AM Maximum Points: 100<br />

Submit as hardcopy to the instructor as well as e-mail to natarajan.meghanathan@jsums.edu<br />

Important: Along with the assignment, each student should submit a cover sheet that has the following<br />

details: Student name, Semester, Assignment number, Date and time of submission of the assignment,<br />

Number of pages of the assignment excluding the cover sheet and Student signature. Assignments<br />

submitted without the cover sheet having all the above required information will not be graded.<br />

Project Description<br />

Get two integers n and k as inputs from the user. Note that n should always be greater than or equal to k.<br />

See the next page for the values of n and k assigned to each student. Implement the <strong>Dynamic</strong><br />

<strong>Programming</strong> algorithm discussed in class to find the binomial coefficient C(n, k) and output this value.<br />

The algorithm and the recursion used are also given below.<br />

Mathematical Formula to compute <strong>Binomial</strong> Coefficient C(n, k): nCk<br />

nC k<br />

n!<br />

=<br />

k!*(<br />

n − k)!<br />

Recursion<br />

Pseudo code for the <strong>Dynamic</strong> <strong>Programming</strong> algorithm to find <strong>Binomial</strong> <strong>Coefficients</strong>


Example<br />

Input Values assigned to each student<br />

Student Name n, k values Student Name Graph File Name<br />

Princess Palmer 20, 5 Andrew Overton 20, 10<br />

Keisha Horton 18, 0 Jarvis Hester 18, 14<br />

Joe Wells 15, 10 Jason Smith 15, 3<br />

Zharian Dawson 16, 7 Victoria O’Harroll 16, 12<br />

David Porter 17, 9 Dominick Sanders 17, 5<br />

Bernard Aldrich 14, 5 Rickeal Lee 19, 8<br />

What to Submit:<br />

• (60 points) Complete Java Source Code to compute the binomial coefficient nCk<br />

• (30 points) Incorporation of the appropriate Java code to evaluate the test cases based on the 6<br />

different Equivalence classes mentioned above. Show screenshots for the inputs you pass for each<br />

test case and the outputs obtained. Document each of your inputs clearly in the report. See next<br />

page for more information on equivalence testing.<br />

• (10 points) Determine the binomial coefficient nCk in paper, <strong>using</strong> the mathematical formula<br />

given.


Software Testing: You need to add sufficient checks in your code to ensure that:<br />

• The values of n and k input by the user are positive (i.e., ≥ 0)<br />

• The value of n ≥ k<br />

• Both n and k cannot be 0.<br />

Equivalence Classes (Test Cases for your Program)<br />

For the first 5 equivalence classes, you can use an appropriate input of your choice. Clearly state what<br />

input values you are passing for each of these 6 equivalence classes:<br />

1) n < k<br />

2) n < 0, for any k<br />

3) k < 0, for any n<br />

4) n = k = 0<br />

5) n = k ≠ 0<br />

6) n ≠ k (Use the input values assigned to you)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!