Lesson 15 of 23
RecursionRecursion
10 min 30 XP
Recursive function தன்னைத்தானே சிறிய input-உடன் அழைக்கும். Base case இல்லையெனில் stack overflow ஆகி program crash ஆகும்.
A recursive function calls itself with a smaller input. Without a base case, the stack overflows and the program crashes.
Example: edit me and press Run
Press Run to see the result here.fib(40) recursive-ஆக மிக மெதுவாக இருக்கும் (O(2ⁿ)). Loop அல்லது memoization பயன்படுத்தினால் O(n). இந்த ஒப்பீடு interview-ல் கேட்கப்படும்.
Recursive fib(40) is very slow (O(2ⁿ)); a loop or memoization makes it O(n). Interviewers love this comparison.