Recursion: A Swift story about recursion

What is recursion?

What’s going on over there? What’s in the box?
The person is an heir to Ghengis Khan if his/her father is named Ghengis Khan, or his/her father or mother is an heir to Ghengis Khan.

A toy problem

We want to count down from the any number a user gives, down to 1. Why? To illustrate recursion (sorry, we need a simple problem before we move on).

if (num < 1) {return}
Execution steps of countDown when given the parameter 2
A recursion tree for fib(4)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store