The following function computes the value of $\binom{m}{n}$ correctly for all legal values $m$ and $n$ ($m ≥1, n ≥ 0$ and $m > n$)
int func(int m, int n) { if (E) return 1; else return(func(m -1, n) + func(m - 1, n - 1)); }
In the above function, which of the following is the correct expression for E?
mC0 = 1 mCm = 1
Hence, (C) is the correct option!
Thanks @ankitgupta.1729 !
$ \textbf{m > n}$
Why we are not considering this condition. Due to it we should not take $m == n$
@KARAN
because those are the conditions to the input of the functions and they can change inside the function like in this case due to recursion.
Answer: C Because $\binom{m}{0}$ = $1$ and $\binom{n}{n}$ = $1$.
@ vijaycs
In the third line it must be
[1/r + 1/(n-r)]
you mistyped – in case of +.
@Ahwan sir!
This code is somewhat similar to the 01KS problem so i think the time complexity given by you must be correct.
64.3k questions
77.9k answers
244k comments
80.0k users