Recursion
Recursion, tail optimization and memoization are important piece of Functional programming. Before jumping into solving complex solutions, I slip on basic structure of recursion lot of times. What is base case and what is recursive step?
When I ask most recursive person at home, got the answer as "until I need a charge". Seriously??? I don't know what algorithm it is!!???. It moves all around without any pattern until completely got drained. ☺
So finding the base case says when to stop.
Another programming example: We are given a denomination of coins/ currency notes and amount of value. We need to identify the minimum number of coins/ currency notes required for calculating that amount.
The base case here -> if total of value is equal to the amount required.
The recursive step -> pick a higher denomination available to reach the amount
The above is not the best solution to this problem. And it just gives the steps and you can't directly use it. We need to cover edge cases and modify code usable. This is just to give an idea.
We will explore more further ...




Comments
Post a Comment