Recursion

Notes

I had problems with recursion too, I think because the mind at first tries to follow in an abstract way and gets lost. You need to switch to concrete thinking, so you need specific things that you can rely on, these 3 things are solid, and you can rely on them if you get lost in recursion:

  1. There is always an exit condition ( or it would run forever , we never want that)

  2. There is always a value that changes and it is passed to the next execution, or otherwise it wouldn't make sense it would be always the same execution and the exit condition would never trigger.

  3. Think like frames of a movie, in paper or whiteboard, write a table with a column for every variable and a row for every step, my first programming teacher taught me this, and 19 years later it save me in a white board interview, it helps to calm down and just go step by step seeing how values evolve.

Links