Skip to main content
2 of 3
added 310 characters in body

You're working in an office. If a question comes up, the person to consult is you. If the person to consult doesn't know the answer, consult their manager. Recurse until you have the answer.

So:

ask( person from, person to ):
  if not: from knows the answer
     ask( from's manager, from )
  tell( from, to )

and invoke this with

ask(me,me)

(You still have to define tell(from,to) and make sure that's a no-op if from==to.)

I like this example because it is not trivially iteratable as tail recursion. This explicitly goes up and down the stack.

Next step: if you ask something of someone, you take out a notepad to record what they tell you. If that person doesn't know, they take out a notepad and ask further. Now you know where stack overflow comes from: there is a bunch of notepads open simultaneously, and they all take up some amount of memory.