This question refers to the number of ways
one can form a committee of k people out of a group of
n people. (This is the binomial coefficient "n choose k".)
Note that n>k, n>=1, k>=1.
The binomial coefficient is defined below:
binom(n,1) = n
binom(n,n) = 1
binom(n,k) = binom(n-1,k) + binom(n-1,k-1)
-
Write a recursive function to evaluate binom(n,k). Remember to check
for invalid parameters.
-
For each of the following, trace the function calls and show what
value is returned: (Note that the call may contain invalid
data, in which case, you should show what the function would do.)
|
1) binom(5,4)
|
2) binom(4,2) | 3) binom(6,3) | 4)binom(2,5) | 5)binom(3,0)
|