| Homework 13DetailsFor this assignment you will implement a simple algorithm and answer
a few questions about it.
-
Write a Java method int choose(int n, int k) that computes the binomial
coefficient:
.
- You can assume that n and k are both non-negative.
- You may not use any Java libraries to assist you.
- Your implementation should be as efficient as possible.
- Make sure you test your method on several inputs.
In particular, you should be able to quickly and correctly compute
choose(8,4), choose(15,7), and choose(100,5).
Each of these is a little harder to get correct than the previous one
for reasons I will let you discover/think about.
- You can check your answers at WolframAlpha using a search like "8 choose 4".
- Print out your code and hand it in at the beginning of class. (You only need
to print the method, not the surrounding class, etc. It is O.K. if you print the whole class as long as your entire choose method is all together on one page.)
- No matter how good your method is, it will not be able to compute choose(100,7). Why not?
- Your method will also very likely not be able to compute
choose(100,6) correctly, but for a slightly different reason.
What it is?
|