Help grasping recursion algorithms
I'm having a really hard time understanding recursion well enough to write any algorithms beyond the absolute basics. Not only are iterative forms a lot more intuitive and easy for me to write, but most of the time they seem to have a lot shorter and simpler code... so I'm definitely not understanding how to write recursive algorithms well at all.
Any help/resources? I think the problem is that I'm missing the middle steps between the basic level of recursion that I feel comfortable with and the actual scenarios (e.g. Project Euler problems) that I want to apply them to.
8 comments · 90% upvoted · other discussions
The easiest way to understand how to write recursive functions is to apply recursion to problems that are naturally recursive, such as tree-walking, expression evaluation and parsing. Here, the recursive solutions will typically be much simpler than iterative ones. You could also look at learning a language which makes recursion the main way of writing functions, such as Haskell or Scheme.
I would also point out that solving Project Euler problems are probably not a good way to learn to be a programmer, though they will teach you a lot about mathematics.
chasecaleb [OP] 1 points · Aug 2013
Good point. Do you have any suggestions on what I should focus on learning or where from? I'm a computer science freshman, so I'm sure I'll learn a lot from my classes, but right now they're incredibly boring and I'd like to get a head start.