#Recursion #ProgrammingJourney #LearningToCode
Hey fellow programmers! 🖥️
At what point in your programming journey did you start feeling comfortable with recursion? Was it a sudden “Aha!” moment or a gradual understanding over time?
I’ve been diving into programming, especially Leetcoding, for about a year now. Despite my background as a CS graduate, I still struggle with coming up with recursive solutions for more complex problems. 🤷♂️
If you’ve been in a similar boat or have some valuable insights to share, I’d love to hear from you! And, if you have any suggestions for helpful resources to improve recursive problem-solving skills, please do share. Here are a few tips that might help:
– Practice regularly with coding challenges that involve recursion
– Break down the problems into smaller, more manageable steps
– Visualize the recursion tree to understand the flow of the program better
Let’s learn and grow together! 🚀 Thanks for your input.
When I was 12 self learning C++ some 28 years ago. If you can understand the stack, you should have no problems understanding recursion.
Why do you need it in the first place? Recursion is just basically a replacement for a loop.
What language you’re trying with recursion? Maybe ur current language is not supposed to be user friendly with it.
Maybe try recursion with some functional language, where’s no build in loops and you’ll have to use it, instead of loop.
When i solved a but of competitive programming tasks that required a depth first search algorithm
Learning Haskell really helped cement the idea for me.
couple weeks in
Tail-recursion is OK for some compilers, that converts it to a loop.
Almost immediately. I learned it after learning about loops. I used it on my first program which was a chess app so it was quite handy. I don’t find basic recursion that hard but some of the backtracking algos can be confusing.
The moment I felt comfortable with recursion was the moment I felt comfortable with recursion.
Recursion is one of those things that professors love to teach, but if you try to commit recursive code to an actual project you will simply not get approval from any reviewer. Recursive code is hard to read, and causes very serious problems in edge cases. There is no case where a recursion can’t be replaced with a FIFO queue, and end up much much cleaner and actually readable.
For example Fibonacci and Factorial are perfect examples where you should never write recursive code! If you try to call recursive code with 20.000 iterations you will kill the entire app with a “Stack Overflow” exception. This requires extra checks to sanitize the inputs and it makes more problems than it solves.
In summary: You will never get comfortable with recursion, because it’s a bad programming pattern, and should not be used outside of some exceptions.
I never found recursion hard to understand at all. It is just function calls of the same function with different arguments.
Write binary search, makes plenty of sense to use recursion there.