Re: Recursive functions



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?

.



Relevant Pages

  • Re: Article on Herbert Schildt, author of C Unleashed, repaired on wikipedia
    ... that deliberately went one beyond the end of the string, ... Within its framework, which sucks, it is a correct program. ... To do this you changed a value parameter to a reference parameter and ... this makes the recursion go wrong. ...
    (comp.programming)
  • Re: Recursive functions
    ... recursion is certainly a natural way of defining the ... it IS totally inappropriate to compute ... not mean "inefficient in a typical C implementation". ... If I had an actual requirement to print the string ...
    (comp.lang.c)
  • Re: Three Kinds of Logical Trees
    ... > I think this is just a representation issue. ... > I do have a number, but I am only ttreating as a string. ... I was attempting to isolate the question of tree structure; ... it's not much of an issue; no one uses recursion much. ...
    (comp.databases.theory)
  • Is this recursion?
    ... This is the ole reverse a string classroom assignment. ... Recursion is soemthing I never quite understood till now but as I ... public static void reversal{ ...
    (comp.lang.java.help)
  • Re: Histogram in XSLT 1.0
    ... Since XSLT's string manipulation capabilities are relatively limited, I agree that the two-stage approach may be simplest. ... You know there's a limited range, so you can have an explicit parameter for each value to carry the count down through the recursion. ... a good XSLT processor would be able to optimize it into a tolerably efficient loop. ...
    (comp.text.xml)