Let P be a procedure that for some inputs calls itself (i.e. is recursive). If…

2018

Let P be a procedure that for some inputs calls itself (i.e. is recursive). If P is guaranteed to terminate, which of the following statement(s) must be true?

I.   P has a local variable
II.  P has an execution path where it does not call itself
III. P either refers to a global variable or has at least one parameter
  1. A.

    I only

  2. B.

    II only

  3. C.

    III only

  4. D.

    II and III only

Attempted by 404 students.

Show answer & explanation

Correct answer: D

The correct statements are II and III.

Statement II is true because a recursive procedure must have a base case (an execution path where it does not call itself) to ensure termination.

Statement III is true because to guarantee termination, the procedure must change its state between calls. This requires either parameters or global variables.

Statement I is false because local variables are not strictly necessary for a procedure to terminate; parameters or globals suffice.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Isro