my code is it correct, if no then modify it plz.
if yes, can you tell me if i just write n==0 return 1 condition then program does not work why ? why i am forced to write two base case conditions.
Do i need to define two base cases every time?
@premang,
Your code seems fine, you can use memoization to reduce time complexity.
Also, you have to give two base cases, because the recurrence is of Fibonacci sequence. I am sure you would have done that already, so know why we used two base cases there.
what is memoization ?
is it ok to write recursive functions without knowing how function calls internally works , Coz i am not able to trace on paper.
@premang,
Its just Fibonacci recurrence, you should know how it works, it is the one of the first things one learns in recursion. Make sure you understand the basics well, things will get complicated ahead.
If you don’t know memoization, leave it for now, it will be taught in your course.
1 Like