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 ll. P has an execution path where it does not call itself II. P either refers to a global variable or has at least one parameter

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 ll. P has an execution path where it does not call itself II. P either refers to a global variable or has at least one parameter Correct Answer II and III only

Explanation

  • It is said that the recursive procedure p will terminate ultimately. If p doesn't have any parameter or doesn't refer to any global variable then p will consist of only local variables. So each time when p will recursively be called then a new copy of local variables will be created in the stack. In this case, we can't track how many times p  is called till now. So p have to refer to at least one global variable or take at least one parameter.
  • Use the global variable or the parameter by imposing a condition that when p will not call itself. At that time only p will terminate.

 

a) the recursive procedure p will only terminate if it has at least one global variable.

b) the recursive procedure p will contain an execution path where it doesn't call itself

so, II and III are true.

option 4 is correct.

Related Questions

Let X be a recursive language and Y be a recursively enumerable but not recursive language. Let W and Z be two languages such that Y̅ reduces to W, and Z reduces to X̅ (reduction means the standard many-one reduction). Which one of the following statements is TRUE?