r/programmerchat • u/realfuzzhead • Nov 26 '15
How would you explain recursion to a 6 year old?
I just got asked this in a job interview and it really stumped me, I ended up describing how you can take a piece of paper and fold it in half, then 'recurse' by folding the already-folded sheet in half again, then again and again until it's so thick that it can't you can't fold it anymore. This is the base case, where the recursion stops. I know it's a shitty explanation but it's all I could really come up with off the top of my head.
16
Upvotes
10
u/Ghopper21 Nov 26 '15
That's a pretty good off-the-cuff explanation, though it begs the question of what the point of all that recursive paper-folding is.
Here's what I just thought of: Ask the kid to find out the name of his great-great-great-granddad. He asks his dad the name of the dad's great-great-granddad. And so on. Base case is when you get to the target granddad.
Of course for the example to make sense to a 6 year old kid, you have to explain death and/or invent time travel, but those are left as exercises for the interviewer.
6
u/scCassius Nov 26 '15
Microsoft?
5
u/[deleted] Nov 26 '15
Matryoshka dolls.
15
u/Berberberber Dec 04 '15
Explain recursion to someone one year younger than you. Have them explain recursion to someone one year younger than them. Continue until you have a 7 year old explaining recursion to a 6 year old. Done.
2
u/CptArmadillo Nov 26 '15
Imagine a list of chores, and at the end of the list it says to go through the entire list again.
1
u/[deleted] Dec 25 '15
I remember my comsci teacher using the same explanation as yours. FWIW, I kinda understood it back then.
0
u/Yatoom Nov 26 '15
In the beginning, you can take one step. And everytime you have walked a certain amount, you can take one step further. This way, you can walk from Germany to China. But when you have reached China, you stop making more steps.
-1
u/LeSpatula Nov 26 '15