You are on page 1of 2

Computer science ISC test set 1

1. What are the disadvantages of iteration?


2. What happens when base case is not defined in a recursive method?
3. What is direct recursion?
4. Which data structure / principle is used to perform recursion?
5. What is augmented recursion?
6. In an Indirect Recursion, in which Recursive Function is the Base Case given?
7. What is head recursion?
8. Can we use return instead of System.out.println() while doing recursion programs?
9. Can we use recursion for every program?
10. Is it fine if we opt for tail recursion in recursive programs?
11. What is the recursive function for prime number?
12.The following function Mystery( ) is a part of some class. What will the function Mystery( ) return
when the value of num=43629, x=3 and y=4 respectively? Show the dry run/working.

int Mystery (int num, int x, int y)


{
if(num<10)
return num;
else
{
int z = num % 10;
if(z%2 == 0)
return z*x + Mystery (num/10, x, y);
else
return z*y + Mystery(num/10, x, y);
}
}

13. The following is a function of some class which checks if a positive integer is a Palindrome number by
returning true or false. (A number is said to be palindrome if the reverse of the number is equal to the
original number.) The function does not use the modulus (%) operator to extract digit. There are some
places in the code marked by ?1?, ?2?, ?3?, ?4?, ?5? which may be replaced by a statement/expression
so that the function works properly.

boolean PalindromeNum(int N)
{
int rev=?1?;
int num=N;
while(num>0)
{
int f=num/10;
int s= ?2?; i. What is the statement or expression at ?1?
int digit = num-?3?; ii. What is the statement or expression at ?2?
rev= ?4? + digit; iii. What is the statement or expression at ?3?
num/= ?5?; iv. What is the statement or expression at ?4?
} v. What is the statement or expression at ?5?
if(rev==N)
return true;
else
return false;
}
14.
Design a class Perfect to check if a given number is a perfect number or not. [A number is said to be perfect
if sum of the factors of the number excluding itself is equal to the original number]
Example: 6 = 1 + 2 + 3 (where 1, 2 and 3 are factors of 6, excluding itself)
Some of the members of the class are given below:
Class name: Perfect
Data members/instance variables:
num: to store the number
Methods/Member functions:
Perfect (int nn): parameterized constructor to initialize the data member num=nn
int sum_of_factors(int i): returns the sum of the factors of the number(num), excluding itself, using a
recursive technique
void check(): checks whether the given number is perfect by invoking the function sum_of_factors() and
displays the result with an appropriate message
Specify the class Perfect giving details of the constructor(), int sum_of_factors(int) and void check(). Define
a main() function to create an object and call the functions accordingly to enable the task.

You might also like