| Homework 13Comments
- Most problems are found in one of the following:
- ADM: The Algorithm Design Manual
- IDMA: An Introduction to Discrete Mathematics and Algorithms
- For full credit, provide context for each problem, show all calculations,
and justify all answers by providing enough comments to explain your reasoning.
- You will lose a significant amount of credit if you do not provide context,
calculations, and justifications for a problem.
- Numbers and/or algebra by themselves are not enough.
A correct answer with no justification will be worth no more than half credit,
and sometimes much less than that.
- Precision is very important. You cannot skip steps, make guesses,
or use flawed logic. Any of these things can lead to incorrect answers.
- Homework assignments must be very neatly written or typeset
(e.g. using Word or OpenOffice).
- You must indicate any assistance/collaboration you had on an assignment as
specified on the Policies page.
- NEW! If a problem asks for an algorithm,
you should give the most efficient algorithm you can find to ensure full credit.
You should also specify the complexity of the algorithm with justification,
whether or not the problem asks for it.
DetailsFor 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?
|