Sabbatical dev

sabbatical devtechnical blog
 

Recursive function walkthrough

Help in understanding recursion

As mentioned in my previous article, not having a computer science degree, I have always felt I could do with spending some time studying some fundamental topics.

So whilst on my sabbatical, I have made studying some classic computer science algorithms one of my top priorities.

To aid my learning I have been reading grokking algorithms and I found that the visualised style of the book really helps me understand the subject matter.

Recursion has come up early on, and after reading the chapter thoroughly, I decided I'd like to expand a little bit on the visualisations in the book, and create an interactive walk-through.

I always enjoy building things, as I find it helps me understand the concepts more clearly, and putting this together has helped burn the topic into my memory.

As stated in the book "Recursion is a coding technique used in many algorithms", so I thought it would be a good idea to ensure that I understood the concept and its inner workings properly.

The problem I chose from the book is:

You’re given an array of numbers. You have to add up all the numbers and return the total. So on passing an array of 2,4,6 to your function it should return 12.

It's not a complex problem, but this walk-through is more about explaining what is happening during the execution of recursive functions, and visualises the JavaScript call stack to give a full overview.

I hope you find the walk-through helpful - just use the simple navigation arrows inside the codepen to step through.


If you feel there is anything wrong with my explanation or it can be improved in anyway, please comment or reach out to me.


Comments

Add a comment