Does ne one know how to answer this question?

Discuss the truth or otherwise of the statement “Recursion and loops are the same thing".

Dani AI

Generated

Short answer: they are not identical in practice, but they are equivalent in what you can compute. Several quick replies appeared above; the useful way to answer the homework question is to explain the formal equivalence and the practical differences, then give a brief example and a troubleshooting note.

Recap of the comparison (practical points):

  • Expressive power: any loop can be written recursively and any recursion can be turned into an iterative loop (often by using an explicit stack). That makes them computationally equivalent.
  • Resource model: recursion normally uses one call frame per level (call stack); iteration reuses variables in a single frame. That affects peak memory and can cause stack-overflow for deep recursion.
  • Performance and tooling: recursive calls incur function-call overhead; some runtimes/compilers perform tail-call elimination (turning certain recursion into iteration), but many mainstream implementations do not, so performance differs by language.
  • Readability and correctness: recursion matches naturally recursive data (trees, divide-and-conquer) and can simplify proofs by induction; loops are often clearer for simple linear iteration and easier to reason about with loop invariants.

Small examples (Python-style):

def fact_iter(n):
    r = 1
    for i in range(2, n+1):
        r *= i
    return r

def fact_rec(n):
    if n <= 1:
        return 1
    return n * fact_rec(n-1)

Troubleshooting / practical advice:

  • If recursion hits depth limits, convert to an iterative version or simulate the call stack explicitly (use your own stack/queue).
  • For algorithms on trees or divide-and-conquer, prefer recursion for clarity unless profiling shows it’s a bottleneck.
  • When asked to “discuss the truth,” state the theoretical equivalence, then list the concrete trade-offs above and include a short code example that demonstrates both forms.

This addresses the core of the thread without repeating earlier one-line answers and gives a compact, testable illustration.

Recommended Answers

All 14 Replies

Recursion is recursive and loops just repeat.

There is no question except your question for us to write your research paper for you.

Better luck next time kiddo, you've been found out.

How I know you're a kiddo: your use of extremely childish language constructs and text messaging shorthand gives you away instantly.

Does ne one know how to answer this question?

Yes. Question answered.

hahaha, Yes I know aswell, two answers in your hand now... :D

worth a try, i guess!!!

wht RU on Abt Jwenting? Dis is prfctly gd grmr!!

Yes. Question answered.

actually I don't believe they are... a loop starts at the beginning goes straight to the end, and then repeats.

a recusrive method/function will start at the beginning and go until it is called again (resursive) and then call a whole new instance of that method with different pararmeters/arguments. It will keep doing this until done, and then it will start to unwind and each function/method will then go to the end, and then rewind to the previous and again go to the end.

>actually I don't believe they are...
The mad literalists answered the only question that was posed:

Does ne one know how to answer this question?

Since it's clearly a homework assignment, nobody with half a brain would just give away the answer. ;) Unless of course the answer is given in such a way as to be too cryptic to be useful, such as my answer.

i would not have responded to this question, but at the same time i did not want the wrong answer being given out... which i think is 10x worse than just been given the answer

Lazy people who want hand outs deserve what they get.

>actually I don't believe they are...
The mad literalists answered the only question that was posed:

Since it's clearly a homework assignment, nobody with half a brain would just give away the answer. ;) Unless of course the answer is given in such a way as to be too cryptic to be useful, such as my answer.

But how can one answer a statement? The OP's question was whether someone can answer something which turns out to not be a question :mrgreen:

Everyone misunderstood his question. He asked if anyone knew. That requires a yes or no answer. So actually it wasn't that bad of a post.

>Everyone misunderstood his question.
No, apparently only paradox misunderstood. Everyone else seemed to get the joke.

haha ... look who the idiot is now! :o :cry:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.