The How SaaS Works series simplifies the complex world of software-as-a-service (SaaS) into the practical fundamentals for anyone involved in SaaS. These are the real-world lessons learned from…
This is in continuation of our previous post in the series .If you have not seen that please have a look to my earlier post in the series
So in previous post we have seen the Top down approach to solve the DP problem . Now we will see the other approach to solve the problem
Bottom Up Approach
Lets understand this by taking the same fibonacci problem again . So here we first focus on the base cases ie we know for fibonacci problem
fib(0) =0 , fib(1) =1 ,fib(2)=1 and so on …
So we iteratively start from the base case and use the already calculated result to calculate the further result . Lets look at the solution to this problem using bottom up approach.
Since we are iterating here from 0 -n once, our time complexity will be O(n) and our space will also be O(n), as we have created a 1D array from 0 to n. This makes our current solution comparable to the top-down solution, although without recursion. This code is likely easier to understand.
I hope now identifying the DP problem and two approaches to solve the DP problem is clear .Lets look up Knapsack problems in our next post .
Till then Stay Tuned !
In the Fear of unknown and what’s going to happen If you chose doing nothing through the course by hiding and avoiding the heart of the problem then it is psychologically very similar to animals in…
Um dia o diabo apareceu no meu quarto. Entre um baseado e doses de conhaque, perguntei o que ele queria. A resposta foi direta: sua vida.
Shelby Sorrel is a 24-year-old who works a desk job in a cubicle for an insurance company. In her spare time, she seriously enjoys food. Shelby has become a local foodie who fell into the title when…