There once was a little girl named Alyssa P. Hacker.
Her dad was acomputer scientist. He worked with computers all day long.
Alyssa always heardhim talking aboutsomething called“recursion”, so oneday she asked him,“Dad, what does‘recursion’ mean?”“Well,” he said,“Recursion is whenyou define aprocedure in terms ofitself.”“I don’t get it,” saidAlyssa.
“Let me put it this way,”her dad said. “You knowthe story ofCinderella, don’t you?” heasked.“Of course! She’s myfavorite princess!” Alyssasmiled.“Do you remember whathappens at the end?” heasked.“Yeah! The prince findsCinderella and they getmarried and live happilyever after!”
“Right!” he said. “Theprince knows that theshoe will only fitCinderella, but hedoesn’t know who sheis, so he must test allof the girls until hefinds her. Since hedoesn’t know howmany girls thereare, he doesn’t knowhow many times hewill have to try thesame test, so he usedlogic to devise amethod of findingCinderella.
He tries the shoe on agirl, and if the shoefits, they can getmarried and live happilyevery after, but if not, hemust move on to thenext girl and try to findCinderella again bytrying the shoe on her.He can only stop oncehe finds the right girl!What the prince wasdoing was like arecursive procedure.”
“Oh!” said Alyssa. “Ithink I get it now!Recursion is like tryingto solve a problem bytrying the same ideaover and over again ondifferent things until itworks.”“That’s pretty close!”her dad told her. “Ithink you’ll be a greatcomputer scientist oneday!”