Dynamic Programming
โ Dynamic Programming
solve problem by breaking down into simple subproblems
solve subproblem once, store the result, avoid redundand computation
find a subproblem with repeated caculation
- Top-Down Dynamic Programming
- memoization
- recursive
- Bottom-Up Programming
- start with solving subproblems, build up solutions to solve large problems.
๐ Divide and Conquer
simmilar in the sence that we divide a problem to solve
but different
- Divide and Conquer: divide problem into smaller problem
- DP: find a repeated caculation(๋ฐ๋ณต๋๋ ์ฐ์ฐ) to solve
โ Conditions for DP
1. Overlapping subproblem
- require repeated caculation
2. Optimal Substructure ์ต์ ๋ถ๋ถ๊ตฌ์กฐ
- can retrieve answer for new sub problem from another subproblem
- ์๋ก์ด ๋ถ๋ถ ๋ฌธ์ ์ ์ ๋ต์ ๋ค๋ฅธ ๋ถ๋ถ ๋ฌธ์ ์ ์ ๋ต์ผ๋ก๋ถํฐ ๊ตฌํ ์ ์๋ค.
โญ๏ธ Memoization
store(memoize) results to avoid recomputation
ํ ๋ฒ ๊ณ์ฐํ ๋ฌธ์ ๋ ๋ค์ ๊ณ์ฐํ์ง ์๋๋ก ์ ์ฅ
๐๐ป Pros
- memoization
- avoid recomputing
- break down into smaller problems
โ Usage
- Shortest path in graph
- fibonacci https://soheeparklee.github.io/posts/CT-1-57/
๐ก Reference
https://www.geeksforgeeks.org/dynamic-programming/
https://gyoogle.dev/blog/algorithm/Dynamic%20Programming.html
This post is licensed under CC BY 4.0 by the author.