Recursive procedures are implemented using:

2017

Recursive procedures are implemented using:

Answer: C. StackConcept: Each function call must eventually return control to exactly the point that invoked it, and when calls are nested, the most recently made call must…

  1. A.

    String

  2. B.

    Queue

  3. C.

    Stack

  4. D.

    Linked List

Attempted by 2502 students.

Show answer & explanation

Correct answer: C

Concept: Each function call must eventually return control to exactly the point that invoked it, and when calls are nested, the most recently made call must finish and return before any earlier call can resume. A Last-In-First-Out (LIFO) structure matches this discipline exactly: an item is pushed when a call begins and popped when it returns, so the most recent entry always comes out first.

Application: Trace a small recursive call, e.g. factorial(3):

  1. factorial(3) begins and calls factorial(2); factorial(2) begins and calls factorial(1); factorial(1) begins and calls factorial(0).

  2. Each call, before making the next one, pushes an activation record onto the run-time structure holding its return address, its parameter, and its local variables.

  3. factorial(0) returns first, so its record is popped first; control returns to factorial(1).

  4. factorial(1) then finishes and its record is popped, returning control to factorial(2), and so on until factorial(3) finally completes.

Cross-check: the unwind order above (0 -> 1 -> 2 -> 3) is exactly the reverse of the call order (3 -> 2 -> 1 -> 0) — the defining LIFO property. A structure that instead released the earliest-made call first would try to resume factorial(3) before factorial(2), factorial(1), and factorial(0) had produced their results, which is impossible; only the LIFO discipline described above supports correct recursive unwinding.

Explore the full course: Bpsc

Loading lesson…