English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

In class we started learning about recursion, and I'd like to know which is better.

2007-02-22 08:18:15 · 6 answers · asked by angmoo 1 in Computers & Internet Programming & Design

6 answers

Recur iteration is best!!!...

2007-02-22 08:21:55 · answer #1 · answered by Kiowa1 5 · 1 0

Our teacher also had this as a discussion when I was in my C programming class.

Based from the concluded discussion, a recursion will be best use for any novice programmers because it shows a step-by-step process of iterating a solution until it terminates when condition is met. Recursion is slower in process but has lesser commands used than iteration.

Iteration is commonly used among programmers. Though it has longer codes than recursion but faster compared to recursion. Iteration can be used to solve to almost any looping problems while recursion can solve to some problems only. Iteration is a bit difficult if you are a novice programmer but as soon as you keep practicing iteration, it will be as easy as counting 1, 2, 3.

A good programmer always practices looping iteratively and recursively. But you have to give focus on looping iteratively because, as to what I said, almost all problems about looping can be solved iteratively.

2007-02-22 19:55:37 · answer #2 · answered by red scar 2 · 0 0

As others have send it depends a lot on what you are doing, and which is easier to code up.

In general though, iteration will give you much better performance when compared to recursion. There is a lot of overhead in recursion since you just keep adding to the function stack.

If you have a problem, though, that can be done easily either way, you are probably better off using iteration.

2007-02-22 16:32:01 · answer #3 · answered by rsmith985 3 · 0 0

Depends on the problem. Recursion can be a cleaner more elegant solution for a certain type of problem but some problems can't be solved or implemented via recursion. Iteration, on the other hand, can be used to solve just about all recursively solvable problems...although it might get kinda ugly.

Also, recursive algorithms can be notoriously hard debug if they are wrong.

Personally, I like recursion better. The algorithms are just cleaner but I fully realize that most problems can't be solved recursively.

2007-02-22 16:27:22 · answer #4 · answered by bytekhan 2 · 0 0

It's not that any one is better, it's which one fits the problem best.

If you just need to do something a finite number of times, there's no need to code it as a recursive routine. Just do it x number of times. Recursion comes in handy when you don't know how many times you'll need to do something and can code it so that the same code can split up the task at hand.



Recursion uses iteration to call itself

2007-02-22 16:21:42 · answer #5 · answered by BigRez 6 · 1 0

depends on what your doing....In general, recursive code can be simpler and shorter than iterative code. But recursive programs can run into the problem of increasing the run time (because of the overhead involved in multiple subprogram calls), and of running out of memory (because of the unseen stack that keeps track of variables and return locations).

2007-02-22 16:25:08 · answer #6 · answered by theguy 2 · 1 0

fedest.com, questions and answers