ISC Questions & Answers: Computer Science - Recursion

1. What are the disadvantages of iteration?

Some disadvantages are: If, for instance, you need to remove some item during your iteration, this cannot be done in many implementations. Same set of variables and code is used for iteration process.

2. What happens when base case is not defined in a recursive method?

It will be an infinite recursion and never ending.

3. What is direct recursion?

Direct recursion is a programming technique in which a call to a method appears in that method's body (i.e., a method calls itself)

4. Which data structure / principle is used to perform recursion?

It represents a Stack data structure and follows the principle of LIFO (Last In First Out).

5. What is augmented recursion?

In augmented recursion, the recursive call, when it happens, comes before other processing in the function (think of it happening at the top, or head, of the function).

6. In an Indirect Recursion, in which Recursive Function is the Base Case given?

Base case is given in any recursive method and is used to terminate the recursive process.

7. What is head recursion?

Augmented recursion is also known as head recursion.

8. Can we use return instead of System.out.println() while doing recursion programs?

Yes. If the recursive method is a returning type then, return has to be used. If it is a non returning type then, System.out.println() is to be used.

9. Can we use recursion for every program?

It depends on the program. If it is a repetitive process then, either iteration or recursion can be used.

10. Is it fine if we opt for tail recursion in recursive programs?

Yes. You may use any type/ classification of recursion.

11. What is the recursive function for prime number?

boolean isprime(int num, int f)
{ if(num==f)
return true;
else if ( num%f==0 || num<2 )
return false;
return isprime(num, f+1);
Eg. isprime( 13,2); // Output: true
isprime ( 16,2); // Output: false

12. If we give negative index (a^(-b)) then how will we calculate power using recursion?

Calculate for positive power (ab) and return 1/ab if the power is negative. Since, a-b is also equal to 1/ab.

13. What is towers of Hanoi?

It is a game having three pegs/sticks with circular disks of different radius placed one top of the other. The game is to move all the disks from the start peg to the end peg. The rules are:

  • You can move only one disk at a time.
  • At no instance, a larger radius disk be placed over a smaller radius disk.