Ask your own question, for FREE!
Computer Science 20 Online
OpenStudy (anonymous):

what is the difference between recursion and iteration in C, and their advantages and disadvantages?

OpenStudy (anonymous):

iteration are sequence of steps which are executed one by one one after another style and for recursion goto http://www.tuhinrawat.co.cc

OpenStudy (anonymous):

iteration its better than recursion iteration its just some steps that repeats a number of times Recursion its a type of function that depends on it self, example factorial: fact(n) = n*fact(n-1) fact(1) = 1; Its quite similar to a itaration as u will repeat almost the same step over till u get to the base case, but its a functon. Iteration its faster than recursion, as calling a function involves several steps using the stack to save registers and other things. Although some compilers that optimizes can notice special cases of recursoin where u can transform them to an iteration (i dont know the english term, but in spanish its "recusion de cola", those where there isnt any instruction after the recursion call)

OpenStudy (anonymous):

"iteration its better than recursion"?!? Try telling that to the monks working on their towers of Hanoi!

OpenStudy (anonymous):

Iteration is not "better" than recursion in all cases. You can express some algorithms in a much cleaner way using recursion. If you know the recursion depth will never be very deep the cost of the extra stack frames is worth it.

OpenStudy (anonymous):

Finally, some languages are based on the concept of recursion. Functional languages are for instance. But in these cases tail recursion is optimized and becomes a loop under the hood.

OpenStudy (anonymous):

Oh and the optimization fedep3 was referring to is indeed tail recursion optimization.

OpenStudy (anonymous):

well what i meant its that iteration its better in time. Of course tons of problems u can see it more easly as a recursion: quicksort, mergesort, algorithm in trees, dfs, etc.

OpenStudy (anonymous):

oh..ok.. thank you so much guys! that made my report! :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!