?

Log in

AlbertJayNock

Recursion

I recently introduced recursion to my data structures class. For those unfamiliar, recursion is when a routine in a computer program invokes itself. Below is an example:


public void factorial(int num)
{
  if (num==0)
    return 1;
  else
    return num*factorial(num-1);
}


I did the usual things. I showed them the above java method, and I showed them what happens when you google the word recursion.
I also told them a story a professor I TA'd for in grad school told his undergraduate class. It's a story you can appreciate even if you still don't quite get recursion.

The story involved a graduate course he was teaching in document retrieval. One of the students was a library science student, and was not as experienced in programming as his classmates. He came to the professor with a program that wasn't working.

The professor looked at it and noticed that he had a recursive subroutine in it. The program was written in PL/I , which requires that all recursive subroutines be labeled as such with a keyword. The professor told him to add the word "recursive" to the subroutine header.

The student had never heard the word recursive before. But he added the necessary keyword and the program worked like a charm.
He understood recursion without ever having heard the word. 

It was worth going to graduate school just to hear that story. It gives students confidence that recursion is not as difficult a concept as they think it is, and it also illustrates the importance of understanding a concept relative to the importance of knowing terminology.

   

Tags:

Comments