recursion vs. iterati
Author Message recursion vs. iterati

In> I have the following program:...
<snip>
In> FUNCTION hp(n,x:integer):integer;
In> BEGIN
In> IF n=0 THEN hp:=1;
In> IF n=1 THEN hp:=2*x;
In> ELSE hp:=2*x*(hp(n-1,x))-2*(n-1)*(hp(n-2,x));
In> END;

In> How would you redifine the hp equation iterativle rather than
In> recursively?

In> Any help would be cool... thanks.

Here's a hint... You need two routines, where one calls the other over and
over. What you have above is one routine calling itself over and over. For
any further help you really should talk to your instructor, and have him
explain the differences between iteration and recursion.

-- Kim Forwood --

/-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-\

%               http://www.*-*-*.com/ ~kforwood/              \$
\$         For what purpose is life, if one cannot live freely?         %
\-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-/

___ Blue Wave/QWK v2.20

Wed, 18 Jun 1902 08:00:00 GMT  recursion vs. iterati

Quote:

> In> I have the following program:...
> <snip>
> In> FUNCTION hp(n,x:integer):integer;
> In> BEGIN
> In> IF n=0 THEN hp:=1;
> In> IF n=1 THEN hp:=2*x;
> In> ELSE hp:=2*x*(hp(n-1,x))-2*(n-1)*(hp(n-2,x));
> In> END;
> In> How would you redifine the hp equation iterativle rather than
> In> recursively?
> In> Any help would be cool... thanks.
>Here's a hint... You need two routines, where one calls the other over and
>over. What you have above is one routine calling itself over and over. For
>any further help you really should talk to your instructor, and have him
>explain the differences between iteration and recursion.

Or more simply just a loop, with everything inside.

Matt

God didn't create the world in seven days--He goofed off for six, then pulled an all-nighter - Anon.

HomePage:  http://ds.dial.pipex.com/matt.parkins/

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages

Powered by phpBB® Forum Software