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. ☺ May be it is the algorithm... 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. For the amount $3.15, we need to pick up 12 quarters, 1 dime and 1 nickel. So total number of coins is 14 coins. The base case here -> if total of value is equal to the amount required. The recursive step -> pick a higher denomination available to re...
Comments
Post a Comment