15% off membership for Easter! Learn more. Close

Explain concept of 'recursion' to grandma?

Asked at Startup
3.1k views
eye 3.1k views eye 3.1k views
Answers (1)
crownAccess expert answers by becoming a member

You'll get access to over 3,000 product manager interview questions and answers

badge Platinum PM
So, the base assumption here is that my grandma is totally unaware of any of the programming concepts. Thus, with the above assumption I would like to give the following example.

 

Hey Grandma!, assume that you are standing in a queue of people and naturally you would want to know how many people are there before you. To know the same, you can move to the side and start counting. But like always, you'll be afraid what if you miss your position in the line.

At this juncture, you'll be trying to ask the person before you on how many are standing ahead of him. Assuming he also doesn't know, he'll naturally ask the person before him. This will continue on and on until the very first person gets the question. Now, the first person would say "0 people are standing ahead of him". The second hearing this, would reply to the 3rd, " 1 person is before him". The 3rd will reply to the 4th, "2 people are before me". This process once again gets on and on until the person before grandma knows how many people are before him and replies the same to you.

 

So this way of getting information by repeatedly doing the same thing until a condition is met is called Recursion. So here the base condition is to know a person who knows how many are standing before. Once the condition is met the answer starts flowing back to the caller. Here the caller was you, Grandma.

 

So the actual definition of recursion is, Solving a problem by using a simpler version of the problem itself.
Access expert answers by becoming a member
0 likes   |  
1 Feedback
badge Platinum PM
Great job explaining to grandma what recursion is.
I think this is such an interesting question and you did really well explaining it.
It would've been bonus points if you had explained when you would use recursion vs. iteration and also what the downside of recursion could be (e.g. neverending which leads to stack overflow)

 

0
Get unlimited access for $12/month
Get access to 2,346 pm interview questions and answers to give yourself a strong edge against other candidates that are interviewing for the same position
Get access to over 238 hours of video material containing an interview prep course, recorded mock interviews by expert PMs, group practice sessions, and QAs with expert PMs
Boost your confidence in PM interviews by attending peer to peer mock interview practices, group practices, and QA sessions with expert PMs
Get unlimited access for $12/month
Get access to 2,346 pm interview questions and answers to give yourself a strong edge against other candidates that are interviewing for the same position
Get access to over 238 hours of video material containing an interview prep course, recorded mock interviews by expert PMs, group practice sessions, and QAs with expert PMs
Boost your confidence in PM interviews by attending peer to peer mock interview practices, group practices, and QA sessions with expert PMs