I am going over recursive functions and i understand how to write basic ones, but I have a question on my study guide that I dont understand.
. Write code for a recursive function named Combinations that computes nCr. Assume that nCr can be computed as follows:
nCr = 1 if r = 0 or if r = n and
nCr = (n-1)C(r-1) + (n-1)Cr
Can someone please help me through this or explain in layman's terms? Thank you!
The question really has all the information. It tells you how to compute nCr - and that a lot of the time, you compute it by computing another nCr (with smaller arguments). So your functions might look like this:
That's translating as literally as I can. Let's see how that works in practice, by computing
Of course we knew that already: