Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #12274

Re: Converting recursive algorithm to an iterative version

From 88888 Dihedral <dihedral88888@googlemail.com>
Newsgroups comp.lang.c++
Subject Re: Converting recursive algorithm to an iterative version
Date 2011-12-09 12:51 -0800
Organization http://groups.google.com
Message-ID <10678810.1375.1323463864546.JavaMail.geo-discussion-forums@pret21> (permalink)
References <618ba19e-c74f-4fcd-a16a-a6542270c73d@j10g2000vbe.googlegroups.com> <4ee1ad88$0$2805$7b1e8fa0@news.nbl.fi>

Show all headers | View raw


On Friday, December 9, 2011 2:41:12 PM UTC+8, Juha Nieminen wrote:
> Ania <anka.s...@gmail.com> wrote:
> > I try to convert my recursive algorithm to an [iterative] one.
> 
>   May I ask why?
> 
>   I think that unless there's a good reason for that, this is a true case
> of premature optimization (in the most negative sense). It is often the
> case that if an algorithm is recursive in nature, trying to implement it
> iteratively (especially if you need an explicit stack) only produces
> significantly longer and more complicated code. If the amount of recursion
> in the original algorithm is less-than-linear (eg. O(log n) recursions),
> then any possible overhead caused by the recursive calls is insignificant.
> 
>   Thus, in such a case, the iterative version will be longer, more
> complicated and with little to no speed benefit. (Hence why it's true
> premature optimization.)

If you are writing programs to be run infrequently for trivial jobs, 
I have to say that in this kind of trivial cases there is no need for any optimization or improvement for this kind of programming. 

But in my experience, codes fine-tued for speed requirements are not low paid 
programmers' jobs in the industry.  
   









 

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Converting recursive algorithm to an iterative version Ania <anka.stepien@gmail.com> - 2011-12-07 15:48 -0800
  Re: Converting recursive algorithm to an iterative version Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-08 08:59 -0500
  Re: Converting recursive algorithm to an iterative version Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-08 06:30 -0800
    Re: Converting recursive algorithm to an iterative version Ania <anka.stepien@gmail.com> - 2011-12-08 08:25 -0800
      Re: Converting recursive algorithm to an iterative version Paavo Helde <myfirstname@osa.pri.ee> - 2011-12-08 12:53 -0600
        Re: Converting recursive algorithm to an iterative version jgk@panix.com (Joe keane) - 2011-12-11 20:36 +0000
          Re: Converting recursive algorithm to an iterative version Paavo Helde <myfirstname@osa.pri.ee> - 2011-12-11 15:37 -0600
            Re: Converting recursive algorithm to an iterative version Ania <anka.stepien@gmail.com> - 2011-12-11 14:26 -0800
  Re: Converting recursive algorithm to an iterative version Larry Evans <cppljevans@suddenlink.net> - 2011-12-08 11:58 -0600
    Re: Converting recursive algorithm to an iterative version Ania <anka.stepien@gmail.com> - 2011-12-08 11:41 -0800
  Re: Converting recursive algorithm to an iterative version Juha Nieminen <nospam@thanks.invalid> - 2011-12-09 06:41 +0000
    Re: Converting recursive algorithm to an iterative version 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-09 12:51 -0800
      Re: Converting recursive algorithm to an iterative version Juha Nieminen <nospam@thanks.invalid> - 2011-12-10 09:54 +0000
        Re: Converting recursive algorithm to an iterative version 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-10 02:14 -0800
          Re: Converting recursive algorithm to an iterative version Juha Nieminen <nospam@thanks.invalid> - 2011-12-10 10:33 +0000
            Re: Converting recursive algorithm to an iterative version 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-10 02:41 -0800
              Re: Converting recursive algorithm to an iterative version 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-10 02:42 -0800
        Re: Converting recursive algorithm to an iterative version Tobias Müller <troplin@bluewin.ch> - 2011-12-10 11:56 +0000

csiph-web