Recursion - Interview Questions - Question 1
Please describe the recursion concept to a 5 years old?
Suggested Answers:
One: Russian dolls. If you open it, then there is "the same" but "smaller" one, until you reach to the most inside one.
Two: Thinking about that you are sitting at the last row of a very large class room. The rows of seats have been defined as starting with the one most close to the front chalkboard (1, 2, 3, ...). The question to ask is which row you are sitting now.
Your can count it from the first row until to your row; but a different way is that: "if the row number of the one before mine is x, then my row is (x + 1)". Then the same procedure can be run until reaching the first row, which can return 1 easily. Then it can be used to return the row numbers for all the rest rows (including yours).
Comments
Post a Comment