How would you teach recursion?

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

Gunslinger08

Lifer
Nov 18, 2001
13,234
2
81
Originally posted by: tfinch2
N Queens problem is a perfect first example

I don't think so. It's a little too complex. You don't want something that has too much built in logic. You're trying to teach basic recursion, not how to solve a problem.
 

BlueFlamme

Senior member
Nov 3, 2005
565
0
0
Ignore all the idiots who believe teaching infinite loops = recursion...


I did a little research, the easiest sort to teach recursion would be a merge sort. Get a deck of cards and pull out all the spades from 2-9, shuffle them up, line them up, and physically show them how recursion works (or create a PPT if you need that as a medium).

EDIT: For their sake, don't use the Tower of Hanoi problem.
 

Jzero

Lifer
Oct 10, 1999
18,834
1
0
Originally posted by: joshsquall
Originally posted by: logic1485
For some people, you may have to teach what a factorial is first. I did not know what a factorial is, and yet I did some programming, but I can't remember how I was taught it.

I think it's safe to assume that most people learn factorials in middle school.

And if not, you can explain it in 3 seconds.