|
From: Ioannis V. <no...@ho...> - 2003-02-14 20:25:15
|
-------Original Message-------=0D =0D From: Per Westermark=0D Date: =D0=E1=F1=E1=F3=EA=E5=F5=DE, 14 =D6=E5=E2=F1=EF=F5=DC=F1=E9=EF=F2 2= 003 5:29:34 =EC=EC=0D To: Louis Godio=0D Cc: Ioannis Vranos; dev...@li...=0D Subject: RE: [Dev-C++] recursion=0D =0D The factorial is faster and more efficient as a loop.=0D =0D In a loop, it may use the input parameter as loop variable, and only need= =0D a temporary for evaluating the product.=0D =0D A recursive solution would duplicate the input parameter and a temporary=0D and a return address for each step of the algorithm.=0D =0D That's why faculty is so bad an example when comparing the two solution=0D methods. While the mathematical definition of the faculty function is=0D recursive, the actual problem isn't recursive in nature.=0D =0D =0D =0D =3D=3D> For generic algorithms a recursive solution is always more defici= ent than the iterative solution. =0D =0D In space because every call has its own instances of the local variables = and also in most cases all the continuous function calls are stored in the st= ack =0D =0D In run-time because of the function calls.=0D =0D =0D Ioannis Vranos=0D =0D * Programming pages: http://www.noicys.freeurl.com=0D * Alternative URL: http://run.to/noicys=20 |