[Tutor] Re: Recursion....what are the best situations to use it?

jsoares at Safe-mail.net jsoares at Safe-mail.net
Thu Apr 14 21:06:36 CEST 2005



I've seen a couple of nice tutorials on recursion, and a lot of awful ones. The latter always trot out the fibonacci and factorial examples for some reason. And that's about it! The good ones showed me how to trace through recursive calls and gave me practical examples(tictactoe, magic squares, Tower of Hanoi, 4-Square, etc)



What I want to know is this: what are other specific situations where a recursive algorithm would be better or easier to program than an iterative one?



I know that the Eight Queens puzzle is a good recursion candidate, but I don't understand why as yet. I'm still on simple recursion, and am just beginning to understand backtracking in a simple example, like adding numbers in an array.



>From what I've read, it seems like two dimensional games or puzzles would be good candidates for recursive programming. Also, things like random maze generation...I saw something on Pierzonski's(sic) Carpet, but I didn't really understand it. I did understand that anything to do with manipulating patterns might be a good recursion candidate.



If this is too general a question, perhaps you can tell me when NOT to use recursion(where it would be inappropriate or inefficient).



I'd certainly like to learn what seems like a powerful tool, but I don't want to use it where I shouldn't.



Any hints appreciated.



John



=================================
John Soares, Webmaster
Family Safe Surfinghttp://www.family-safe-surfing.net
jsoares at family-safe-surfing.net
jsoares at safe-mail.net

"Your best bet for online family-friendly resources"
=================================



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050414/ac31f9ca/attachment.html


More information about the Tutor mailing list