The Hanoi problem is a good demonstration of recursion. The student
can visualize himself physically moving the disks from one peg to
another. Numeric problems are too abstract. Way back in maybe 1984 I
wrote an article for "Computer Languages" magazine describing the
Hanoi problem. I think I provided both Forth and BASIC code. I don't
remember the issue date, but it was the issue with interviews of Knuth
and Wirth.
All of the Forth code in that rosettacode website is ugly. Who wrote
that stuff?
I have QuickSort in the novice package. My default is HeapSort though
--- a big part of why I chose HeapSort is that I could avoid messing
with recursion this way. Notice how I use MACRO: for the sub-
functions, and they access the local variables in the calling
function. This lets me use locals rather than globals, which makes the
whole thing reentrant, but I don't have to reinitialize the locals
repeatedly as I would in a recursive function --- so I get reentrancy
*and* efficiency. This is one of many examples of code in the novice
package that was originally written using global variables (which
helps for testing), and then upgraded to use MACRO: and local
variables after I had it working.
Mostly though, I like HeapSort because it has very little variance in
how long it takes to run. QuickSort varies a lot depending upon how
ordered the data is initially. This is worthwhile in the novice
package because it could be used by anybody on any data --- I have no
way of predicting what the data will look like. If you do know what
the data will look like, it might be possible to chose a better
algorithm (such as the BucketSort, which is very fast but can only be
used with certain kinds of data).
The advantage of QuickSort is primarily that it is so simple that it
can be memorized (by comparison, I have to look up HeapSort every time
that I implement it) --- QuickSort is worthwhile to memorize, as
writing a sort function on the blackboard is a typical job-interview
task --- you would look pretty novice if the only sort algorithm
you've memorized is the BubbleSort. LOL It is all nonsense though,
because memorizing algorithms isn't a part of any computer programming
job. Real programmers have libraries of this stuff available --- you
don't actually stop in the middle of writing your application program
to figure out sort algorithms.