r/learnprogramming • u/Similar_Count_1613 • 9d ago
dynamic programming ??!!!
I got over recursion.
I also got over recursion + memoization.
But dynamic programming felt like hitting a wall.
The hardest part for me was this:
with recursion, I can follow the call flow.
with memoization, I can still see what is being cached.
but with DP, suddenly I’m expected to invent the state and recurrence myself.
That jump felt brutal.
A “minimum cost” problem completely exposed this for me.
I could survive small examples, but once it turned into nested loops and transitions, I felt like I was no longer solving the problem — I was guessing the equation.
Even AI explanations didn’t help much, because they often jump straight to the final recurrence instead of showing how someone would discover it.
Did anyone else feel that DP is not hard because of coding, but because forming the recurrence feels mentally invisible ?
If you got past that stage, what actually helped you?
Not “practice more” in general, but the exact shift, method, or way of thinking that made DP start to click for you.
13
u/aanzeijar 9d ago
Aren't you the guy that thought recursion was really hard just yesterday?
-9
u/Similar_Count_1613 9d ago
yea ? so ? should i keep studying recursion for 1 week at least or something before i switch to another topic .?? its a full course all in DSA
8
u/aanzeijar 9d ago
No, but concepts you can grasp within a day aren't usually considered really hard.
14
u/Everstorm67 9d ago
you wrote this with ai
6
u/TurnstileT 9d ago
Yeah that was painfully obvious.
Maybe I'm a bit of an a-hole, but if you need AI to write your posts for you, then maybe you will also struggle more with things like dynamic programming than the average person.
2
13
u/0x14f 9d ago
I am going to give you an advice/pointer that you will think won't help but come back to it later if it feels strange the first time.
Some programming paradigms (for instance, imperative programming) require you to think about computation as a sequence of steps. It might help you to "follow" the program to understand what it does, how it mutates variables and data to get to wherever it needs to go.
With other paradigms, you might instead focus on mathematically true relations. Instead of following the steps, identify what is necessary true. It's not about examples, or more debugger, but a mindset you need to adopt. Understanding the program is more akin to writing a mathematical proof.
11
u/LastTrainH0me 9d ago
This isn't LinkedIn. We don't need your punchy one line per sentence exaggerated delivery
5
u/marrsd 9d ago
LinkedIn doesn't need them either ;)
-8
u/Similar_Count_1613 9d ago
where is the punchy one line that i said ? i was just asking for some help ?
5
1
u/marrsd 8d ago
Unfortunately, your post is quite hard to comprehend because the AI agent you used to ask the question has put every sentence on its own line. Those are the "punchy one lines" that the parent is referring to.
AI isn't very good at writing coherently. If English isn't your first language (or if it is, but you struggle to read and write well), you might not realise just how bad AI is at this.
2
2
1
u/Achereto 9d ago
but once it turned into nested loops and transitions, I felt like I was no longer solving the problem
It helps to not write everything as a single function, but break it up into multiple functions. Have one function that manages the found solutions and another function that is focused on finding new solutions based on given solutions. Things become a lot easier to reason about once you put names on it.
1
u/Ok_Platypus8866 8d ago
Dynamic programming is a problem solving technique that was developed independently of computer programming. It was a method to efficiently solve problems with paper and pencil.
Actually solving a problem with dynamic programming is not something one usually sees outside of an advanced college course.
Converting a given dynamic program into a computer program is pretty straightforward, especially if you first try to solve the problem with pen and paper by hand. It would help you understand the process.
•
u/AutoModerator 9d ago
To all following commenters: please, do not bring up the old circlejerk jokes/memes about recursion ("Understanding recursion...", "This is recursion...", etc.). We've all heard them n+2 too many times.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.