1 2 3 4 |
|
Which of the following is equivalent to the recursive function shown above?
Assumptions
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
If we write it step by step:
fun(a,b) -> a+fun(a,b-1) or 1 a + fun(a,b- 1 ) -> a + a + fun(a,b-2) or 2 a + fun(a,b- 2 ) -> .... -> ( b )a + fun(a,b- b ) -> ( b )a + 0 -> b.a
At every step b is decreasing by one and and another a is being added . There will come a time when a will be added b times and as the second argument of function will become zero the recursive function will end. Hence, the answer will be b.a or a.b .