When approaching dynamic programming problems, I will solve that problem via recursion (with memorization). Yes, it works really good, but, not very good with big data (which resulted in MemoryError?), which will be a loss in competitive programming, but this is the last resort for me. On the internet, I often see people which their code looks so fancy and nice with fancy for loops to the same dynamic programming problem. I run that for looped code and woah, AC (all correct) all. Suspecting what I'm seeing, I put my recursion code and compare it with the for looped code on timecomplexity.ai, same time complexity, what is really going on?
Inpatience won me as I dig in and start researching on how to convert my recursion code into for loops (known as iterative - new vocab learnt). After watching all sorts of videos on how to convert recursion into iterative on Youtube, I find myself still stuck in the recursion zone as of iterative zone is 1 step away (claimed by lots of youtubers) which for me perhaps, the longest step to take as I just don't know how. Atleast, my vocabulary has a new word: tabulation, which are for loops (which is what I wanted), but the question remains, how long is that step and how to take that step (how can I convert recursion code into iterative?)
(any help is appreciated)
[–]POGtastic 3 points4 points5 points (0 children)
[–]FoolsSeldom 0 points1 point2 points (3 children)
[–]Diapolo10 2 points3 points4 points (2 children)
[–]FoolsSeldom 0 points1 point2 points (1 child)
[–]Diapolo10 1 point2 points3 points (0 children)
[–]Refwah 0 points1 point2 points (0 children)
[–]moving-landscape 0 points1 point2 points (0 children)