Re: newbie question: recursion algorithm and iterative algorithm
From: Matthew Huntbach (mmh_at_dcs.qmw.ac.uk)
Date: 02/10/04
- Next message: Harpo: "Re: newbie question: recursion algorithm and iterative algorithm"
- Previous message: Norbert E. Fuchs: "Re: newbie question: recursion algorithm and iterative algorithm"
- In reply to: Norbert E. Fuchs: "Re: newbie question: recursion algorithm and iterative algorithm"
- Next in thread: Joachim Schimpf: "Re: newbie question: recursion algorithm and iterative algorithm"
- Reply: Joachim Schimpf: "Re: newbie question: recursion algorithm and iterative algorithm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 10 Feb 2004 16:37:41 GMT
Norbert E. Fuchs <fuchs@ifi.unizh.ch> wrote:
> In article <3f349ddf.0402100313.4fb1d20b@posting.google.com>,
> chenyu468@yahoo.com (chenyu) wrote:
>> "In addition he says that every recursion algorithm can be translated
>> into iterative algorithm." <==== right??
>>
>>
>> I don't whether there exists an easy transform algorithm to do the
>> translation job or not. Or the existance is proved but transform
>> depends on everyone's technique and knowledge.
>>
>> Could you explain it to me?
> Concerning the transformation "recursion" -> "iteration" look for "tail
> recursion optimisation" in a Prolog textbook, for instance Sterling &
> Shapiro.
Prolog doesn't have iteration. Iteration requires a mutable state,
which Prolog doesn't have. Of course, you can model iteration by tail
recursion in Prolog, and the implementation may implement it by iteration.
But conceptually, it's still recursion, and I doubt the novice programmer
will see it as anything but recursion.
The answer to chenyu's question is that if you're using Prolog, no,
recursion cannot be translated to iteration because Prolog doesn't
have iteration.
But more subtlely, recursion can be converted to iteration by making
implicit the stack which is implicit in a sequence of recursive
calls. So the professor was right, recursive algorithms can always
be converted to iterative algorithms. In practice you can do the same
in Prolog providing you have the ability to visualise tail recursion as
iteration.
Matthew Huntbach
- Next message: Harpo: "Re: newbie question: recursion algorithm and iterative algorithm"
- Previous message: Norbert E. Fuchs: "Re: newbie question: recursion algorithm and iterative algorithm"
- In reply to: Norbert E. Fuchs: "Re: newbie question: recursion algorithm and iterative algorithm"
- Next in thread: Joachim Schimpf: "Re: newbie question: recursion algorithm and iterative algorithm"
- Reply: Joachim Schimpf: "Re: newbie question: recursion algorithm and iterative algorithm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|