0

Which data structure can be used to "eliminate" recursion from a recursive program? Array, stack, queue, or list? How is it used to that end?

When I eliminate recursion from the program computing factorial $n! = n(n-1)!$, I replace recursion with a loop. But I don't see how to do a similar transformation in general.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
user1917769
  • 301
  • 5
  • 12

1 Answers1

1

Let me restate your question: Which data structure does the CPU use to implement recursion? This data structure is knows as the call stack. As you can imagine, it's a stack. I strongly suggest that you consult the Wikipedia page (or any other source) and try to understand why a stack is used and how it works. This is much more important than answering a multiple-choice question.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514