What example of recursion should I use for my AP CS class?

Started by
11 comments, last by SunTzu 17 years ago
I'm a senior in high school and I have a presentation to explain and demonstrate recursion to my class tomorrow. It's only a high school course, and many of the other students do not have much interest in the class (which is sad). As such, I should probably keep it pretty basic. Does anyone have any suggestion on examples I can use for how to demonstrate recursion to them? I was thinking of just recursively sorting an array, but I was wondering if I should do anything more creative. Thanks for any suggestions.
Advertisement
Are you going to be graded on how well they learn the material you present to them? If not, then the Towers of Hanoi may be fun. If so, though, something simpler like finding files in a directory tree could be interesting and still understandable for most folks.

If there's a mathematical twist to the course, then maybe computing the factorial of a number would be good.

All these are relatively basic, and shouldn't be too hard to teach.

Best of luck tomorrow, and let us know how it goes!
-jouley
Towers of Hanoi would be good, I agree. The only problem with that is it was already done in the text book, so it would only be redundant to do it again.

I like the idea of computing a factorial. Thanks for the suggestion.
Depth-first search to find the exit in a maze?
yeah a factorial algorithm was the first thing to come to mind. It's always getting used as an example in text books ;)
Personally I'm partial to merge sort, but most people probably would not find it interesting. Probably going with depth first search to go through a maze would be the best. Problem there is getting a really simple version of it. For me and I think for a lot of other people recursion can be quite confusing the first time. Whatever you do keep it very very simple.
QuickSort
Factorial. It's like a two line function, and - as was said above - it is a great beginner example for recursion.

Towers of Hanoi. Classic example; first "complicated" thing I learned regarding recursion...in high school I learned that, I might add. (Immediately there after they had me balancing binary trees by hand - which involves recursion - so brace yourself. <3)
    Recursion        See "Recursion".


But yea, factorial was my first problem in Scheme I had to do some time ago.

If you want something a little more complex try searching for captured Go pieces.
It took me a couple of hours to figure that one out,
but I don't think it's to complicated to explain once you've written the code.

This topic is closed to new replies.

Advertisement