Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdfacc51

Browse files
Fix typos in intro-to-dp.md (#1411)
* Fix typo in intro-to-dp.md* Fix grammatical error in intro-to-dp.md* Fix typo in intro-to-dp.md
1 parenta5953a5 commitdfacc51

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

‎src/dynamic_programming/intro-to-dp.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tags:
77

88
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.
99

10-
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:
10+
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:
1111

1212
```cpp
1313
intf(int n) {
@@ -25,7 +25,7 @@ Our recursive function currently solves fibonacci in exponential time. This mean
2525
2626
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!
2727
28-
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 previouslycalcuated 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!
28+
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 previouslycalculated 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!
2929
3030
```cpp
3131
const int MAXN = 100;
@@ -88,7 +88,7 @@ This approach is called top-down, as we can call the function with a query value
8888
Until now you've only seen top-down dynamic programming with memoization. However, we can also solve problems with bottom-up dynamic programming.
8989
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.
9090

91-
To create a bottom-up approach for fibonacci numbers, weinitilize the base cases in an array. Then, we simply use the recursive definition on array:
91+
To create a bottom-up approach for fibonacci numbers, weinitialize the base cases in an array. Then, we simply use the recursive definition on array:
9292

9393
```cpp
9494
constint MAXN =100;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp