CSCI 255 Fall 2013
Introduction to Algorithms and Discrete Structures
Archived Class
Charles Cusack
Computer Science
Hope College
Main
Schedule
Grading
Gradebook

Policies
Advice
College
    Policies

Notes
Programs
Tutorials

CSCI 385
MATH 160
Others

Admin

Homework 13

Details

For this assignment you will implement a simple algorithm and answer a few questions about it.

  1. 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.)
  2. No matter how good your method is, it will not be able to compute choose(100,7). Why not?
  3. Your method will also very likely not be able to compute choose(100,6) correctly, but for a slightly different reason. What it is?