Post

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

  1. Top-Down Dynamic Programming
    • memoization
    • recursive
  2. 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

๐Ÿ’ก 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.