Re: Recursive functions
- From: "Bill Pursell" <bill.pursell@xxxxxxxxx>
- Date: 1 Apr 2007 22:05:12 -0700
On Apr 1, 11:05 pm, Keith Thompson <k...@xxxxxxx> wrote:
"Bill Pursell" <bill.purs...@xxxxxxxxx> writes:
On Apr 1, 9:10 pm, Lauri Alanko <l...@xxxxxx> wrote:
In article <1175456107.493063.221...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Bill Pursell <bill.purs...@xxxxxxxxx> wrote:
Because it is totally inappropriate to use a recursive
function to compute the length of a string.
"Totally inappropriate" apparently means here "inefficient on a
typical C implementation". That is certainly true, but not always
crucial. Even the space performance isn't an issue if the lengths of
all argument strings are known to have a reasonable bound.
Efficiency aside, recursion is certainly a natural way of defining the
length of a sequence.
It is a natural way of defining the length of a finite sequence
in a mathematical setting. It is not completely unnatural
to define the length of a finite sequence in terms of recursion
on a computer. However, it IS totally inappropriate to compute
the value using recursion. Totally inappropriate does
not mean "inefficient in a typical C implementation". It
is, rather, a euphimism for "completely boneheaded".
In real-world C code, I agree. <OT>In Lisp-like languages, it might
be perfectly appropriate.</OT>
But homework assignments are not real-world code; consider how easily
we can tell the difference when people post here asking for help.
You make many excellent points, which I'll try to remember
when I start to make up multiplication flash cards in hex
for my kids. :) I've never taught any programming courses,
but I've taken a few, and have always been very frustrated
by the lack of practicality. As a result, I find myself
spending a lot of time getting burned by triviata that
I should have known better about. Perhaps it is true
that certain things can only be learned by being burned,
but the purist in me wants to believe that is not the
case.
As to the Fibonacci example for recursion: why have
I never seen a programming example of the closed
form solution? There's a nice exposition here:
http://mathproofs.blogspot.com/2005/04/nth-term-of-fibonacci-sequence.html
(I only glanced at it, so I won't vouch for accuracy).
Why bother with the iterative solution, when you
can just compute the value?
.
- Follow-Ups:
- Re: Recursive functions
- From: Keith Thompson
- Re: Recursive functions
- References:
- Recursive functions
- From: Harry
- Re: Recursive functions
- From: Bill Pursell
- Re: Recursive functions
- From: Harald van Dijk
- Re: Recursive functions
- From: Bill Pursell
- Re: Recursive functions
- From: Lauri Alanko
- Re: Recursive functions
- From: Bill Pursell
- Re: Recursive functions
- From: Keith Thompson
- Recursive functions
- Prev by Date: Re: malloc() and alignment
- Next by Date: Difference between for n while
- Previous by thread: Re: Recursive functions
- Next by thread: Re: Recursive functions
- Index(es):
Relevant Pages
|