Question: I need to write a java function for this and I'm stuck. Combination(long N, long X): This function returns the number of ways X objects

I need to write a java function for this and I'm stuck.

Combination(long N, long X): This function returns the number of ways X objects can be drawn from N objects ignoring the order in which the objects are drawn. To reduce the problem of integer overflow, your algorithm should:

a. For special cases X = 0 and X = N, the return value is 1.0.

b. Calculate C(N,X) or C(N,N-X) depending on whether X or N-X is smaller (same value).e.g To calculate C(50,47), calculate C(50,3) instead.

c. Alternate multiplies and divides (in a loop).e.g. C(25,4) = 25 / 1 * 24 / 2 * 23 / 3 * 22 / 4d. Convert (cast) all values to double while you calculate the result.e.g. double comb = 1.0Then in the loop: comb = comb*(double)(N-i)/(double)(i + 1)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!