Java Reference
In-Depth Information
You have to make the problem simpler. Instead of asking the person in front of
you what place you are in line, ask that person what place he or she is in line:
I want to know what place I am in line.
So, what place are you in line?
Let me try to figure that out.
The key difference is that the person in front of you is closer to the front of the
line. Suppose, for example, that you're 4th in line. The person in front of you is 3rd
in line, which is closer to the front. But notice that you're asking the person in front
of you to think about the exact same kind of question you're considering: You're both
trying to figure out your places in line. That's where recursion comes in—the problem
recurs because each of you wants to answer the same question.
The idea is to set up a chain reaction of people, all asking the person in front the
same question:
What place are you in line?
What place are you in line?
What place are you in line?
Search WWH ::




Custom Search