From 63c16212dbb549acf3416affb0e18d540935937f Mon Sep 17 00:00:00 2001 From: Konstantinos Alatzas Date: Thu, 9 Jan 2025 15:55:58 +0000 Subject: [PATCH 1/3] Fix typo in intro-to-dp.md --- src/dynamic_programming/intro-to-dp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dynamic_programming/intro-to-dp.md b/src/dynamic_programming/intro-to-dp.md index ab2d3a1a3..17ccbade5 100644 --- a/src/dynamic_programming/intro-to-dp.md +++ b/src/dynamic_programming/intro-to-dp.md @@ -88,7 +88,7 @@ This approach is called top-down, as we can call the function with a query value Until now you've only seen top-down dynamic programming with memoization. However, we can also solve problems with bottom-up dynamic programming. Bottom-up is exactly the opposite of top-down, you start at the bottom (base cases of the recursion), and extend it to more and more values. -To create a bottom-up approach for fibonacci numbers, we initilize the base cases in an array. Then, we simply use the recursive definition on array: +To create a bottom-up approach for fibonacci numbers, we initialize the base cases in an array. Then, we simply use the recursive definition on array: ```cpp const int MAXN = 100; From 6a3416a7f9c671e6bf853c85c22e9c61494cf5aa Mon Sep 17 00:00:00 2001 From: Konstantinos Alatzas Date: Thu, 9 Jan 2025 15:57:51 +0000 Subject: [PATCH 2/3] Fix grammatical error in intro-to-dp.md --- src/dynamic_programming/intro-to-dp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dynamic_programming/intro-to-dp.md b/src/dynamic_programming/intro-to-dp.md index 17ccbade5..a66bf7f80 100644 --- a/src/dynamic_programming/intro-to-dp.md +++ b/src/dynamic_programming/intro-to-dp.md @@ -7,7 +7,7 @@ tags: The essence of dynamic programming is to avoid repeated calculation. Often, dynamic programming problems are naturally solvable by recursion. In such cases, it's easiest to write the recursive solution, then save repeated states in a lookup table. This process is known as top-down dynamic programming with memoization. That's read "memoization" (like we are writing in a memo pad) not memorization. -One of the most basic, classic examples of this process is the fibonacci sequence. It's recursive formulation is $f(n) = f(n-1) + f(n-2)$ where $n \ge 2$ and $f(0)=0$ and $f(1)=1$. In C++, this would be expressed as: +One of the most basic, classic examples of this process is the fibonacci sequence. Its recursive formulation is $f(n) = f(n-1) + f(n-2)$ where $n \ge 2$ and $f(0)=0$ and $f(1)=1$. In C++, this would be expressed as: ```cpp int f(int n) { From 6eb6f819f3a73e30e0ae8ab241873596d8570120 Mon Sep 17 00:00:00 2001 From: Konstantinos Alatzas Date: Thu, 9 Jan 2025 16:38:55 +0000 Subject: [PATCH 3/3] Fix typo in intro-to-dp.md --- src/dynamic_programming/intro-to-dp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dynamic_programming/intro-to-dp.md b/src/dynamic_programming/intro-to-dp.md index a66bf7f80..8bc33fd82 100644 --- a/src/dynamic_programming/intro-to-dp.md +++ b/src/dynamic_programming/intro-to-dp.md @@ -25,7 +25,7 @@ Our recursive function currently solves fibonacci in exponential time. This mean To increase the speed, we recognize that the number of subproblems is only $O(n)$. That is, in order to calculate $f(n)$ we only need to know $f(n-1),f(n-2), \dots ,f(0)$. 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! -Each recursive call will check against a lookup table to see if the value has been calculated. This is done in $O(1)$ time. If we have previously calcuated it, return the result, otherwise, we calculate the function normally. The overall runtime is $O(n)$. This is an enormous improvement over our previous exponential time algorithm! +Each recursive call will check against a lookup table to see if the value has been calculated. This is done in $O(1)$ time. If we have previously calculated it, return the result, otherwise, we calculate the function normally. The overall runtime is $O(n)$. This is an enormous improvement over our previous exponential time algorithm! ```cpp const int MAXN = 100;