|
From: Ioannis V. <no...@ya...> - 2001-11-13 19:52:34
|
I astrongly agree with St0fF here. Recursion has time cost due to continuous function calls and space cost because of the storage of the function calls in the stack (or in the automatic storage if you prefer). This applies to fibonacci too. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com * Alternative URL: http://run.to/noicys > -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of St0fF 64 > Sent: Tuesday, November 13, 2001 5:48 PM > To: DevCPP; Williams, Timothy W. > Subject: Re: [Dev-C++] Efficiency >=20 >=20 > Hi! > As I said, iteration speeds it all up because no unneccessary=20 > Stacking, > meaning: push return address, recursive recall, push return=20 > address, recursive recall, ... , recursive recall, return=20 > solution, pop return address, return solution, ... , pop=20 > return address, return solution, finished. This is the=20 > negative effect of recursion. In the iterative version we do=20 > counting instead of accessing the stack. The dealing with=20 > return addresses and the stack is not used in iteration. =20 > Thats why it is faster. St0fF. |