r/learnprogramming • • Apr 05 '22

Name one programming/comp sci concept you never understood and if you understand it, try to explain it to them

Name a programming concept such as virtual functions, pointers, certain algorithms, etc that you always had a hard time understanding and why.

Someone else who reads yours and does understand it, try to explain it to them to help them learn

1.6k Upvotes

738 comments sorted by

View all comments

Show parent comments

1

u/The_Crypter Apr 06 '22

No, it was a typo on my part.

Where was that pointed out because all I see is people saying Memorization + Recursion= Dynamic Programming.

1

u/Knaapje Apr 06 '22 edited Apr 06 '22

I thought there were more, but now I can only find this one: https://www.reddit.com/r/learnprogramming/comments/twuf18/comment/i3j3yq1/?utm_source=share&utm_medium=web2x&context=3

Edit: and this one: https://www.reddit.com/r/learnprogramming/comments/twuf18/comment/i3kkrzl/?utm_source=share&utm_medium=web2x&context=3 (simplified, losing some details)

Where was that pointed out because all I see is people saying Memorization + Recursion= Dynamic Programming.

Then they are frankly misinformed, misremembering or misrepresenting the essence in an effort to summarize.

The "programming" in Dynamic Programming comes from the mathematical jargon, where it means optimization (like in Linear Programming, Quadratic Programming, Semi-Definite Programming, etc.), which is a lot older than the modern meaning for the word programming. I agree the name is bad, but there's more to it than memoization and recursion. Essentially, since it's actually "dynamic optimization" it's really about solving specific types of optimization problems. Specifically, those with overlapping sub-problems and optimal substructure, i.e. you can meaningfully subdivide the problem, and solving the subproblems helps. There's two approaches which usually follow from this perspective: a forward DP algorithm and a backward DP algorithm. The former usually involves tabulation and iteration, and the latter usually memoization and recursion.

Dijkstra's algorithm is an example of a forward DP algorithm, and also calculating the Fibonacci sequence using iteration is a forward DP algorithm. Calculating it recursively is the backward DP algorithm, and memoization is only the technique to prevent unnecessary work in the latter case.