recategorized
1,830 views
2 votes
2 votes

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?

  1. $P$ has a local variable
  2. $P$ has an execution path where it does not call itself
  3. $P$ either refers to a global variable or has at least one parameter 
  1. I only
  2. II only
  3. III only
  4. II and III only
recategorized

1 Answer

Best answer
8 votes
8 votes

It is said that the recursive procedure p will terminate ultimately.If p don't have any parameter or don'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 howmany times p  is called till now.So p have to refer atleast one global variable or take atleast one parameter.

Along with that we have to 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.

So D is correct option.

selected by
Answer:

Related questions

5 votes
5 votes
2 answers
1
Arjun asked Apr 22, 2018
8,559 views
Consider the following program{ int x=1; printf("%d",(*char(char*)&x)); }Assuming required header files are included and if the machine in which this program is executed ...
5 votes
5 votes
3 answers
2
Arjun asked Apr 22, 2018
5,636 views
Consider the following declaration :structaddr { char city[10]; char street[30]; int pin; }; struct { char name[30]; int gender; struct addr locate; } person, *kd = &pers...
1 votes
1 votes
2 answers
3