To Recur(sion) or to Iterate?That is the question

This is a discussion on To Recur(sion) or to Iterate?That is the question within the C Programming forums, part of the General Programming Boards category; Hi people i suppose Recursion can always be translated into iteration any comments?? also recursion is also often the inefficient ...

  1. #1
    Registered User jasrajva's Avatar
    Join Date
    Oct 2001
    Posts
    99

    Question To Recur(sion) or to Iterate?That is the question

    Hi people

    i suppose
    Recursion can always be translated into iteration
    any comments??

    also recursion is also often the inefficient way to solve aproblem but sometimes it is the most intuitive way

    for eg
    to traverse a bin tree recursion is by defn of the traversal (
    Left Root Right
    or any combination of the above)

    is very intuitive(to me atleast)

    so when should i use recursion and when iteration?

    That is The Question

    (Sorry Bill Shakespeare i regret having mangled your words but..
    couldnt resist )
    Last edited by jasrajva; 11-07-2001 at 08:45 AM.
    jv

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    so when i should use recursion and when iteration?
    I would use recursion if that solution was easier to program than an iterative one as long as there is no chance of overrunning the stack space.If the levels of recursion get too deep then you will corrupt the stack and crash.Iterative solutions are safer but in the end its really down to what you are trying to achieve. If speed is an issue then an iterative solution will always run faster than a recursive solution because of the cost of calling functions repeatedly.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User jasrajva's Avatar
    Join Date
    Oct 2001
    Posts
    99
    ok

  4. #4
    junior member mix0matt's Avatar
    Join Date
    Aug 2001
    Posts
    144
    i was taught t o bang my head against the freakin' wall to find an iterative solution to an intuitively recursive problem. if that didn't work, try some more. if i wake up on the floor with a bruised forehead, i use the recursive solution....
    THIS IS NOT JUST A CHRONICLING OF THINGS WE HAVE DONE IN THE PAST BUT OUR RISE TO POWER.

  5. #5
    Sayeh
    Guest
    Actually, recursion is a powerful and useful tool. It is extremely elegant, and wasteful only as regards stackspace.

    As with all things, _moderation is the key_.

    Use recursion where stackspace and performance are not critical factors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. iteration and recursion question
    By Stonehambey in forum C++ Programming
    Replies: 3
    Last Post: 03-19-2008, 06:16 PM
  2. simple recursion question
    By salvadoravi in forum C Programming
    Replies: 4
    Last Post: 12-30-2007, 06:53 AM
  3. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  4. Recursion vs multiple functions
    By PJYelton in forum C++ Programming
    Replies: 4
    Last Post: 12-29-2002, 07:52 PM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 02:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21