You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1411/dynamic_programming/intro-to-dp.html
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6669,7 +6669,7 @@ <h1 id="introduction-to-dynamic-programming">Introduction to Dynamic Programming
6669
6669
<h2id="speeding-up-fibonacci-with-dynamic-programming-memoization">Speeding up Fibonacci with Dynamic Programming (Memoization)<aclass="headerlink" href="#speeding-up-fibonacci-with-dynamic-programming-memoization" title="Permanent link">¶</a></h2>
6670
6670
<p>Our recursive function currently solves fibonacci in exponential time. This means that we can only handle small input values before the problem becomes too difficult. For instance, <spanclass="arithmatex">$f(29)$</span> results in <em>over 1 million</em> function calls!</p>
6671
6671
<p>To increase the speed, we recognize that the number of subproblems is only <spanclass="arithmatex">$O(n)$</span>. That is, in order to calculate <spanclass="arithmatex">$f(n)$</span> we only need to know <spanclass="arithmatex">$f(n-1),f(n-2), \dots ,f(0)$</span>. Therefore, instead of recalculating these subproblems, we solve them once and then save the result in a lookup table. Subsequent calls will use this lookup table and immediately return a result, thus eliminating exponential work! </p>
6672
-
<p>Each recursive call will check against a lookup table to see if the value has been calculated. This is done in <spanclass="arithmatex">$O(1)$</span> time. If we have previously calcuated it, return the result, otherwise, we calculate the function normally. The overall runtime is <spanclass="arithmatex">$O(n)$</span>. This is an enormous improvement over our previous exponential time algorithm!</p>
6672
+
<p>Each recursive call will check against a lookup table to see if the value has been calculated. This is done in <spanclass="arithmatex">$O(1)$</span> time. If we have previously calculated it, return the result, otherwise, we calculate the function normally. The overall runtime is <spanclass="arithmatex">$O(n)$</span>. This is an enormous improvement over our previous exponential time algorithm!</p>
0 commit comments