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  
 
 [ 2 post ] 

 Relevant Pages 

1. recursion vs. iteration

2. TTable vs TQuery vs TwwQuery vs TwwTable - SPEED

3. BDE vs ADO vs Apollo

4. dBase vs Paradox vs Interbase

5. Performance Paradox vs Access vs Other

6. Delphi:Paradox vs Delphi:SQL Anywhere vs Delphi:FoxPro via Apollo

7. PARADOX vs BTRIEVE vs FOXPRO??

8. BP 7.0 vs VB vs Delphi

9. ASM Opt.: XOR vs MOV vs INC/DEC

10. VB vs Delphi vs C/C++

11. Delphi vs Visual Foxpro vs MS Access

12. Personal Oracle 7 vs Paradox 7 vs Local Interbase

 

 
Powered by phpBB® Forum Software