27. Dynamic Programming
-----------------------------------------------------------------------------------------------------------------------------
NOTE-
memoization tends to store value of sub problems in some map/table
Recursion mean top to down means reqd ans se base case tak jaao
Tabulation means bottom to up means base case se reqd ans tak jaao
---------------------------------------------------------------------------------------------------------------
1. declare a dp array, considering the size of the sub problems (e.g., fibonacci mein recursion tree mein f(n) se f(0) tak jaate hue total n+1 nodes milenge at max )
2. store answer for every sub problem which is being computed
3. checking if subproblem is previously solved
-----------------------------------------------------------------------------------------------------------------------------
MEMOIZATION-
Tabulation method-
go from base case to reqd ans
1. base cases se initial values likhlo dp array ki
2. recursive relation mein fn ki jagah dp likhlo and loop m lagado starting idx dekh k
--------------------------------------
optimizing space- (instead of array we will use variables)- O(1) space








Comments
Post a Comment