|
From: Ioannis V. <no...@ho...> - 2003-02-14 13:20:52
|
-------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 2:38:47 =EC=EC=0D To: Jaap de Wolff=0D Cc: dev...@li...=0D Subject: RE: [Dev-C++] recursion=0D =0D I think you got a bit confused about terminology.=0D =0D Looping and iteration is actually the same thing.=0D =0D =0D =3D=3D> Yes you are right.=0D =0D =0D =0D However, recursion is not anything that should be specifically avoided.=0D It's a question of what problem to solve.=0D =0D The trivial example of the faculty function seems to be the most quoted=0D example for the use of a loop instead of recursion, but the example is=0D quite bad, since it's faculty is easier to implement and runds faster as = a=0D loop.=0D =0D There are matematical rules that makes it possible to rewrite any=0D iterative function into a recursive function. And in the same way, any=0D recursive function may be converted to use state queues to store the=0D recursive state.=0D =0D Use recursion when recursion results in faster run-time, or an easier=0D implementation. In other cases, select an iterative approach.=0D =0D =0D =3D=3D> Recursion resulting to faster run-time is something close to the impossible. I agree with the "easier implementation" + "while it does not introduce significant run-time and space costs".=0D =0D =0D =0D Examples where recursion faster and/or easier:=0D - light-tree evaluation in a ray tracer.=0D - parsing of mathematical expressions=0D - some recursively defined functions, such as Ackerman=0D - regular expression pattern matching=0D =0D =0D =3D=3D> The "faster" thing is tough to prove. I agree with the "easier".=0D =0D =0D =0D Ioannis Vranos=0D =0D * Programming pages: http://www.noicys.freeurl.com=0D * Alternative URL: http://run.to/noicys=20 |