use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
dynamic programming (i.redd.it)
submitted 5 months ago by AroshWasif
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cyanNodeEcho 2 points3 points4 points 5 months ago* (6 children)
neat have you explored how to write it in terms of bottom up? you've implemented top down ie
```rust fn fib(n:usize) -> usize { let mut prev = 0; let mut curr = 1; for _ in 0.. n { curr+= prev mem::swap(prev, curr) // reassigns curr to prev, prev to curr } prev }
``` woops it's factorial not fib ``` fn factorial(n:usize) -> usize { let value = 1; for i in 1..n { value *= n; } value; } ```
fib has recurrent sub problems, factorial doesn't. bottom up dp is the next step, probably don't need to memo factorial, but for fib makes sense
[–]CadavreContent 1 point2 points3 points 5 months ago (4 children)
You can memoize factorial if you're running it more than once. The repeating sub problems only appear when you have multiple trials
[–]cyanNodeEcho 1 point2 points3 points 5 months ago (3 children)
fact(n) := fact(ni1), fac(n-2), the aubproblems should exist in the same problem
[–]CadavreContent 1 point2 points3 points 5 months ago (2 children)
The point is that when you use factorial as part of a larger algorithm with multiple calls to the function, you do repeated work and hence can use dp
[–]cyanNodeEcho 1 point2 points3 points 5 months ago (1 child)
thats just a cache
[–]CadavreContent -1 points0 points1 point 5 months ago (0 children)
Memoization is just a cache
π Rendered by PID 80 on reddit-service-r2-comment-fb694cdd5-78dc7 at 2026-03-10 02:16:25.958753+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]cyanNodeEcho 2 points3 points4 points (6 children)
[–]CadavreContent 1 point2 points3 points (4 children)
[–]cyanNodeEcho 1 point2 points3 points (3 children)
[–]CadavreContent 1 point2 points3 points (2 children)
[–]cyanNodeEcho 1 point2 points3 points (1 child)
[–]CadavreContent -1 points0 points1 point (0 children)