

MCQOPTIONS
Saved Bookmarks
This section includes 144 Mcqs, each offering curated multiple-choice questions to sharpen your Java knowledge and support exam preparation. Choose a topic below to get started.
1. |
Iteration requires more system memory than recursion. |
A. | True |
B. | False |
Answer» C. | |
2. |
How many times is ‘a’ printed when the following C code is executed? |
A. | 9 times |
B. | 10 times |
C. | 0 times |
D. | Infinite number of timesView Answer |
Answer» E. | |
3. |
Which of these is not true about recursion? |
A. | Making the code look clean |
B. | A complex task can be broken into sub-problems |
C. | Recursive calls take up less memory |
D. | Sequence generation is easier than a nested iteration |
Answer» D. Sequence generation is easier than a nested iteration | |
4. |
What happens if the base condition isn’t defined in recursive programs? |
A. | Program gets into an infinite loop |
B. | Program runs once |
C. | Program runs n number of times where n is the argument given to the function |
D. | An exception is thrown |
Answer» B. Program runs once | |
5. |
Which of the following statements is false about recursion? |
A. | Every recursive function must have a base case |
B. | Infinite recursion can occur if the base case isn’t properly mentioned |
C. | A recursive function makes the code easier to understand |
D. | Every recursive function must have a return value |
Answer» E. | |
6. |
Observe the following Python code? |
A. | Both a() and b() aren’t tail recursive |
B. | Both a() and b() are tail recursive |
C. | b() is tail recursive but a() isn’t |
D. | a() is tail recursive but b() isn’tView Answer |
Answer» D. a() is tail recursive but b() isn’tView Answer | |
7. |
What will be the output of the following Python code? |
A. | 011 |
B. | 110 |
C. | 3 |
D. | Infinite loopView Answer |
Answer» C. 3 | |
8. |
Fill in the line of the following Python code for calculating the factorial of a number. |
A. | num*fact(num-1) |
B. | (num-1)*(num-2) |
C. | num*(num-1) |
D. | fact(num)*fact(num-1)View Answer |
Answer» B. (num-1)*(num-2) | |
9. |
What will happen when the below code snippet is executed? |
A. | The code will be executed successfully and no output will be generated |
B. | The code will be executed successfully and random output will be generated |
C. | The code will show a compile time error |
D. | The code will run for some time and stop when the stack overflowsView Answer |
Answer» E. | |
10. |
Which of the following problems can’t be solved using recursion? |
A. | Factorial of a number |
B. | Nth fibonacci number |
C. | Length of a string |
D. | Problems without base case |
Answer» E. | |
11. |
Recursion is a method in which the solution of a problem depends on ____________ |
A. | Larger instances of different problems |
B. | Larger instances of the same problem |
C. | Smaller instances of the same problem |
D. | Smaller instances of different problems |
Answer» D. Smaller instances of different problems | |
12. |
If the height of a binary tree is 54, how many null pointers are there as children? |
A. | 1267 |
B. | 358 |
C. | 56 |
D. | 255 |
Answer» E. | |
13. |
Every recursive algorithm must have the problem of ________ |
A. | overhead of repeated function calls |
B. | collision of different function calls |
C. | searching for all duplicate elements |
D. | make only two recursive calls |
Answer» B. collision of different function calls | |
14. |
Which of the following functions generates new data at each step of a method? |
A. | corecursive function |
B. | structural recursive function |
C. | unirecursive function |
D. | indirect function |
Answer» B. structural recursive function | |
15. |
In which of the following problems recurrence relation holds? |
A. | Optimal substructure |
B. | Tower of Hanoi |
C. | Hallmark substitution |
D. | Longest common subsequence |
Answer» C. Hallmark substitution | |
16. |
The mutual recursion is also termed as ______ |
A. | indirect recursion |
B. | constructive recursion |
C. | generative recursion |
D. | definitive recursion |
Answer» B. constructive recursion | |
17. |
The argument of each recursive call is the content of a field of the original output. This definite characteristic belongs to which of the following function? |
A. | Structurally recursive function |
B. | Generativity recursive function |
C. | General function |
D. | Indirect recursive function |
Answer» B. Generativity recursive function | |
18. |
_______ recursion consists of multiple self-references. |
A. | binary recursion |
B. | single recursion |
C. | multiple recursion |
D. | coinductive recursion |
Answer» D. coinductive recursion | |
19. |
How many types of self-referential recursive data are there in computer programs? |
A. | 6 |
B. | 2 |
C. | 10 |
D. | 4 |
Answer» C. 10 | |
20. |
________ is the consequence of dynamic programming. |
A. | Bellman equation |
B. | Frobenius equation |
C. | Linear equation |
D. | Boolean expression |
Answer» B. Frobenius equation | |
21. |
Which of the following is contained in a recursive grammar? |
A. | semantic rules |
B. | production rules |
C. | recursive language |
D. | recursive function |
Answer» C. recursive language | |
22. |
Which is bigger in size Stack Memory or Heap Memory? |
A. | Stack Memory |
B. | Heap Memory |
C. | - |
D. | - |
Answer» C. - | |
23. |
What is the maximum number of levels in a Recursion? |
A. | 8 |
B. | 16 |
C. | 32 |
D. | No limit |
Answer» E. | |
24. |
In most of the scenarios, a recursive method returns ____. |
A. | void |
B. | Some value or object |
C. | - |
D. | - |
Answer» C. - | |
25. |
To end a recursive method a RETURN statement is usually kept inside ___. |
A. | IF block |
B. | ELSE block |
C. | IF or ELSE block |
D. | None |
Answer» D. None | |
26. |
A Recursive method does not need to return a value always. State TRUE or FALSE. |
A. | TRUE |
B. | FALSE |
C. | - |
D. | - |
Answer» B. FALSE | |
27. |
What is the output of the below Java program with recursion? |
A. | 4 3 2 1 |
B. | 3 2 1 |
C. | 3 2 1 0 |
D. | Compiler error |
Answer» C. 3 2 1 0 | |
28. |
It is difficult to write a program with recursion than using multiple loops. State TRUE or FALSE. |
A. | FALSE |
B. | TRUE |
C. | - |
D. | - |
Answer» C. - | |
29. |
A Java program with recursion can be completed with few lines of code when compared to using Loops. State TRUE or FALSE. |
A. | FALSE |
B. | TRUE |
C. | - |
D. | - |
Answer» C. - | |
30. |
Attempting to call a method recursively without a proper RETURN statement leads to ___. |
A. | Stack Overflow errors |
B. | Buffer Overflow errors |
C. | Compile-time errors |
D. | ALL |
Answer» B. Buffer Overflow errors | |
31. |
Recursion usually stops when the Java Runtime encounters an IF or ELSE statement with a RETURN statement. State TRUE or FALSE. |
A. | FALSE |
B. | TRUE |
C. | - |
D. | - |
Answer» C. - | |
32. |
Which is the common problem with Recursive methods in Java? |
A. | StackOverflowError |
B. | IndexOutOfBoundsException |
C. | OutOfMemoryError |
D. | None |
Answer» B. IndexOutOfBoundsException | |
33. |
Which is better in terms of memory utilization Recursion or Loops in Java? |
A. | Recursion |
B. | Loops |
C. | - |
D. | - |
Answer» C. - | |
34. |
Uses are Recursion in Java are___. |
A. | Traversing folders and files on a disk |
B. | Traversing the nodes of a Binary Tree |
C. | Evaluating Nth order equations and Factorials |
D. | All the above |
Answer» E. | |
35. |
Recursion in Java applies to ___. |
A. | Constructors |
B. | Variables |
C. | Methods |
D. | Blocks |
Answer» D. Blocks | |
36. |
Java uses Stack type memory instead of Heap type memory in implementing Recursion because of ___ feature of STACK. |
A. | FIFO (First In First Out) |
B. | LIFO (Last In First Out) |
C. | Round Robin |
D. | None |
Answer» C. Round Robin | |
37. |
Java uses ___ type of memory to implement Recursion. |
A. | Heap |
B. | Stack |
C. | Register |
D. | None |
Answer» C. Register | |
38. |
Check the below code and state whether it is called Recursion in Java? |
A. | TRUE |
B. | FALSE |
C. | - |
D. | - |
Answer» C. - | |
39. |
Recursion in Java is a way of calling the method from within the same method. State TRUE or FALSE. |
A. | TRUE |
B. | FALSE |
C. | - |
D. | - |
Answer» B. FALSE | |
40. |
Consider the following code snippet to find the smallest element in an array:Which of the following lines should be inserted to complete the below code? |
A. | arr[i] > min_element |
B. | arr[i] < min_element |
C. | arr[i] == min_element |
D. | none of the mentioned |
Answer» C. arr[i] == min_element | |
41. |
Consider the following iterative code snippet to find the largest element:Which of the following lines should be inserted to complete the below code? |
A. | arr[i] > max_element |
B. | arr[i] < max_element |
C. | arr[i] == max_element |
D. | none of the mentioned |
Answer» B. arr[i] < max_element | |
42. |
How many times is the function recursive_get_len() called when the following code is executed? |
A. | 6 |
B. | 7 |
C. | 8 |
D. | 9 |
Answer» D. 9 | |
43. |
Consider the following recursive implementation used to find the length of a string:Which of the following lines should be inserted to complete thebelow code? |
A. | 1 |
B. | len |
C. | recursive_get_len(s, len+1) |
D. | 1 + recursive_get_len(s, len+1) |
Answer» E. | |
44. |
Consider the following code snippet to find the largest element in a linked list:Which of the following lines should be inserted to complete the below code? |
A. | temp->next != 0 |
B. | temp != 0 |
C. | head->next != 0 |
D. | head != 0 |
Answer» C. head->next != 0 | |
45. |
Consider the following recursive implementation to find the largest element in an array:Which of the following lines should be inserted to complete the below code? |
A. | max_of_two(arr[idx], recursive_max_element(arr, len, idx)) |
B. | recursive_max_element(arr, len, idx) |
C. | max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1)) |
D. | recursive_max_element(arr, len, idx + 1) |
Answer» D. recursive_max_element(arr, len, idx + 1) | |
46. |
How many times is the function recursive_min_element() called when the following code is executed? |
A. | 9 |
B. | 10 |
C. | 11 |
D. | 12 |
Answer» C. 11 | |
47. |
Consider the following code snippet to find the smallest element in a linked list:Which of the following lines should be inserted to complete the below code? |
A. | temp > min_num |
B. | val > min_min |
C. | temp->val < min_num |
D. | temp->val > min_num |
Answer» D. temp->val > min_num | |
48. |
What is the output of the following code: |
A. | 5 |
B. | 1 |
C. | runtime error |
D. | garbage value |
Answer» D. garbage value | |
49. |
How many times will the function recursive_get_min() be called when the following code is executed? |
A. | 4 |
B. | 5 |
C. | 6 |
D. | 7 |
Answer» C. 6 | |
50. |
Consider the following recursive implementation to find the largest element in a linked list:Which of the following arguments should be passed to the function max_of two() to complete the below code? |
A. | temp->val,recursive_get_max(temp->next) |
B. | temp, temp->next |
C. | temp->val, temp->next->val |
D. | none of the mentioned |
Answer» B. temp, temp->next | |