100 moderate-level MCQs on Basics of Programming and Data Structures for the IBPS SO
IT Officer exam, including solutions:
1. Which of the following is not a valid C++ data type?
o a) int
o b) float
o c) real
o d) char
o Answer: c) real
o Explanation: C++ does not have a data type named real; it uses float or
double for real numbers.
2. What is the result of the expression 5 / 2 in C++?
o a) 2
o b) 2.5
o c) 2.0
o d) 2.5 (floating-point division)
o Answer: a) 2
o Explanation: In C++, integer division truncates the decimal part, so 5 / 2
results in 2.
3. Which of the following is a characteristic of Object-Oriented Programming
(OOP)?
o a) Encapsulation
o b) Polymorphism
o c) Inheritance
o d) All of the above
o Answer: d) All of the above
o Explanation: Encapsulation, polymorphism, and inheritance are all
fundamental characteristics of OOP.
4. In Java, which of the following is used to declare a method that does not return
any value?
o a) void
o b) int
o c) return
o d) null
o Answer: a) void
o Explanation: In Java, void is used to declare a method that does not return a
value.
5. What is the purpose of the this pointer in C++?
o a) To refer to the current object
o b) To allocate memory dynamically
o c) To return the address of the object
o d) To refer to a base class
o Answer: a) To refer to the current object
o Explanation: The this pointer is used to refer to the current object in C++.
6. Which of the following data structures uses Last In First Out (LIFO) order?
o a) Stack
o b) Queue
o c) Array
o d) Linked List
o Answer: a) Stack
o Explanation: A stack follows LIFO (Last In First Out) order.
7. In Java, how do you initialize an array of integers?
o a) int[] arr = new int[5];
o b) int arr = new int[5];
o c) int arr[5] = new int;
o d) int[] arr = new int;
o Answer: a) int[] arr = new int[5];
o Explanation: In Java, arrays are initialized with the new keyword and
specifying the size in square brackets.
8. What is the time complexity of accessing an element in an array?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: a) O(1)
o Explanation: Accessing an element in an array is done in constant time, O(1).
9. Which of the following is not a valid access specifier in C++?
o a) public
o b) private
o c) protected
o d) hidden
o Answer: d) hidden
o Explanation: C++ has public, private, and protected access specifiers,
but not hidden.
10. In Java, what is the default value of a boolean variable?
o a) true
o b) false
o c) null
o d) 0
o Answer: b) false
o Explanation: In Java, the default value of a boolean variable is false.
11. What is the purpose of the new keyword in C++?
o a) To create a new object or allocate memory
o b) To call a method
o c) To declare a variable
o d) To define a class
o Answer: a) To create a new object or allocate memory
o Explanation: The new keyword in C++ is used to allocate memory
dynamically and create new objects.
12. Which of the following is a linear data structure?
o a) Stack
o b) Queue
o c) Linked List
o d) All of the above
o Answer: d) All of the above
o Explanation: Stack, queue, and linked list are all linear data structures.
13. What is the primary difference between a stack and a queue?
o a) Stack uses FIFO, while queue uses LIFO
o b) Stack uses LIFO, while queue uses FIFO
o c) Stack uses random access, while queue uses sequential access
o d) Stack is dynamic, while queue is static
o Answer: b) Stack uses LIFO, while queue uses FIFO
o Explanation: A stack follows LIFO (Last In First Out) order, while a queue
follows FIFO (First In First Out) order.
14. Which of the following is not an OOP principle?
o a) Encapsulation
o b) Inheritance
o c) Polymorphism
o d) Recursion
o Answer: d) Recursion
o Explanation: Recursion is a programming technique, not an OOP principle.
15. In C++, which operator is used to access members of a class?
o a) .
o b) ->
o c) ::
o d) &
o Answer: a) .
o Explanation: The . operator is used to access members of a class.
16. What is the time complexity of inserting an element at the beginning of a linked
list?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: a) O(1)
o Explanation: Inserting an element at the beginning of a linked list is done in
constant time, O(1).
17. Which of the following operations is not typically performed on a stack?
o a) Push
o b) Pop
o c) Enqueue
o d) Peek
o Answer: c) Enqueue
o Explanation: Enqueue is an operation performed on a queue, not a stack.
18. Which data structure is used to implement recursion in programming
languages?
o a) Stack
o b) Queue
o c) Linked List
o d) Array
o Answer: a) Stack
o Explanation: Recursion is implemented using a stack data structure to
manage function calls.
19. What is the primary use of a priority queue?
o a) To manage elements with priorities, where the highest priority element is
served first
o b) To maintain elements in a sorted order
o c) To access elements randomly
o d) To implement a stack
o Answer: a) To manage elements with priorities, where the highest priority
element is served first
o Explanation: A priority queue ensures that elements with higher priority are
accessed before those with lower priority.
20. Which of the following is not a type of linked list?
o a) Singly Linked List
o b) Doubly Linked List
o c) Circular Linked List
o d) Binary Linked List
o Answer: d) Binary Linked List
o Explanation: Binary Linked List is not a standard type of linked list. Singly,
doubly, and circular linked lists are standard types.
21. In Java, how is a class defined?
o a) class ClassName { }
o b) class ClassName() { }
o c) def ClassName { }
o d) class ClassName : { }
o Answer: a) class ClassName { }
o Explanation: In Java, a class is defined using the syntax class ClassName {
}.
22. What is the default access specifier for members of a class in C++?
o a) private
o b) public
o c) protected
o d) default
o Answer: a) private
o Explanation: By default, members of a class in C++ are private.
23. Which of the following is an example of a non-linear data structure?
o a) Stack
o b) Queue
o c) Tree
o d) Array
o Answer: c) Tree
o Explanation: Trees are non-linear data structures, unlike stacks, queues, and
arrays which are linear.
24. What is the main advantage of using a linked list over an array?
o a) Dynamic size allocation
o b) Faster access time
o c) Better memory locality
o d) Random access capability
o Answer: a) Dynamic size allocation
o Explanation: Linked lists allow dynamic size allocation, unlike arrays which
have a fixed size.
25. In C++, which keyword is used to create a new instance of a class?
o a) new
o b) create
o c) instantiate
o d) make
o Answer: a) new
o Explanation: The new keyword is used to create a new instance of a class in
C++.
26. What is the time complexity of searching for an element in a sorted array using
binary search?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: c) O(log n)
o Explanation: Binary search has a time complexity of O(log n) for searching
in a sorted array.
27. Which of the following is a fundamental principle of OOP that ensures that the
details of an object are hidden?
o a) Encapsulation
o b) Inheritance
o c) Polymorphism
o d) Abstraction
o Answer: a) Encapsulation
o Explanation: Encapsulation ensures that the details of an object are hidden
from the outside world.
28. What is the purpose of the return keyword in a function?
o a) To exit from the function and optionally return a value
o b) To call another function
o c) To define a function
o d) To declare a variable
o Answer: a) To exit from the function and optionally return a value
o Explanation: The return keyword is used to exit from a function and
optionally return a value to the caller.
29. Which of the following data structures allows for efficient insertion and deletion
from both ends?
o a) Stack
o b) Queue
o c) Deque (Double-ended Queue)
o d) Linked List
o Answer: c) Deque (Double-ended Queue)
o Explanation: A deque allows efficient insertion and deletion from both ends.
30. What is the time complexity of accessing an element in a singly linked list?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: b) O(n)
o Explanation: Accessing an element in a singly linked list requires traversing
from the head to the desired node, which takes O(n) time.
31. Which of the following is not a standard library function in C++?
o a) printf()
o b) scanf()
o c) cout
o d) out()
o Answer: d) out()
o Explanation: out() is not a standard library function in C++. Functions like
printf(), scanf(), and cout are part of the standard library.
32. In Java, which method is automatically called when an object is created?
o a) Constructor
o b) Destructor
o c) Main
o d) finalize
o Answer: a) Constructor
o Explanation: In Java, a constructor is automatically called when an object is
created.
33. What is the primary purpose of the virtual keyword in C++?
o a) To allow for dynamic method binding and polymorphism
o b) To define a constant value
o c) To declare a static variable
o d) To create an abstract class
o Answer: a) To allow for dynamic method binding and polymorphism
o Explanation: The virtual keyword enables dynamic method binding and
polymorphism in C++.
34. Which of the following data structures is used for implementing depth-first
search (DFS)?
o a) Queue
o b) Stack
o c) Array
o d) Linked List
o Answer: b) Stack
o Explanation: Depth-first search (DFS) is implemented using a stack data
structure.
35. What is the worst-case time complexity of insertion in a binary search tree
(BST)?
o a) O(1)
o b) O(log n)
o c) O(n)
o d) O(n^2)
o Answer: c) O(n)
o Explanation: In the worst case, a binary search tree (BST) can become
skewed, resulting in O(n) time complexity for insertion.
36. In C++, what does the & operator do when used with a variable?
o a) Returns the address of the variable
o b) Returns the value of the variable
o c) Performs a bitwise AND operation
o d) Declares a reference to the variable
o Answer: a) Returns the address of the variable
o Explanation: The & operator returns the address of the variable in C++.
37. Which of the following is not a valid loop construct in Java?
o a) for
o b) while
o c) do-while
o d) loop
o Answer: d) loop
o Explanation: Java has for, while, and do-while loops, but not a loop
construct.
38. What is the time complexity of deleting an element from a hash table?
o a) O(1) on average
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: a) O(1) on average
o Explanation: Deleting an element from a hash table generally has an average
time complexity of O(1).
39. Which of the following is not a type of polymorphism in C++?
o a) Compile-time polymorphism
o b) Runtime polymorphism
o c) Template polymorphism
o d) Function overloading
o Answer: c) Template polymorphism
o Explanation: Template polymorphism is not a standard type of polymorphism
in C++. The standard types are compile-time and runtime polymorphism.
40. What is the time complexity of searching for an element in a balanced binary
search tree (BST)?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: c) O(log n)
o Explanation: Searching in a balanced binary search tree (BST) has a time
complexity of O(log n).
41. In Java, which keyword is used to create an instance of a class?
o a) new
o b) create
o c) class
o d) instance
o Answer: a) new
o Explanation: The new keyword is used to create an instance of a class in Java.
42. Which of the following data structures is best suited for implementing a breadth-
first search (BFS)?
o a) Stack
o b) Queue
o c) Array
o d) Linked List
o Answer: b) Queue
o Explanation: Breadth-first search (BFS) is implemented using a queue data
structure.
43. What is the space complexity of storing an array of size n?
o a) O(n)
o b) O(1)
o c) O(log n)
o d) O(n^2)
o Answer: a) O(n)
o Explanation: The space complexity of storing an array of size n is O(n).
44. Which of the following is true about a doubly linked list?
o a) Each node has a reference to the previous and next nodes
o b) Each node has a reference to only the next node
o c) Each node has a reference to only the previous node
o d) It does not support bidirectional traversal
o Answer: a) Each node has a reference to the previous and next nodes
o Explanation: In a doubly linked list, each node has references to both the
previous and next nodes.
45. What is the time complexity of accessing an element in a linked list by index?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: b) O(n)
o Explanation: Accessing an element in a linked list by index requires
traversing the list, which takes O(n) time.
46. Which of the following data structures is typically used for implementing
recursion?
o a) Queue
o b) Stack
o c) Array
o d) Linked List
o Answer: b) Stack
o Explanation: Recursion is typically implemented using a stack data structure
to manage function calls.
47. Which of the following methods is used to remove an element from a stack?
o a) Pop
o b) Push
o c) Enqueue
o d) Dequeue
o Answer: a) Pop
o Explanation: The pop method is used to remove an element from a stack.
48. What is the time complexity of inserting an element into a sorted array?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: b) O(n)
o Explanation: Inserting an element into a sorted array requires shifting
elements, resulting in O(n) time complexity.
49. Which of the following operations can be performed in constant time for a
doubly linked list?
o a) Insertion at the beginning
o b) Deletion at the end
o c) Searching for an element
o d) Accessing an element by index
o Answer: a) Insertion at the beginning
o Explanation: Insertion at the beginning of a doubly linked list can be done in
constant time, O(1).
50. In C++, which operator is used to access a class member through a pointer?
o a) .
o b) ->
o c) ::
o d) &
o Answer: b) ->
o Explanation: The -> operator is used to access class members through a
pointer in C++.
51. What is the purpose of the final keyword in Java?
o a) To prevent method overriding and inheritance
o b) To define a constant value
o c) To create an abstract class
o d) To specify a class as final
o Answer: a) To prevent method overriding and inheritance
o Explanation: The final keyword in Java is used to prevent method
overriding and inheritance.
52. Which data structure is used to implement a priority queue?
o a) Binary Heap
o b) Stack
o c) Queue
o d) Linked List
o Answer: a) Binary Heap
o Explanation: A priority queue is typically implemented using a binary heap.
53. In Java, what does the super keyword refer to?
o a) The superclass of the current object
o b) The current object
o c) A static method
o d) A method in the current class
o Answer: a) The superclass of the current object
o Explanation: The super keyword is used to refer to the superclass of the
current object in Java.
54. What is the time complexity of finding the minimum element in a binary heap?
o a) O(1)
o b) O(log n)
o c) O(n)
o d) O(n^2)
o Answer: a) O(1)
o Explanation: The minimum element in a binary heap can be found in constant
time, O(1).
55. Which of the following is not a method of the java.lang.String class?
o a) length()
o b) substring()
o c) append()
o d) toUpperCase()
o Answer: c) append()
o Explanation: The append() method is not a part of the java.lang.String
class; it is part of the StringBuilder class.
56. In C++, what is the output of cout << 10 / 3;?
o a) 3
o b) 3.3333
o c) 3.0
o d) 3.3333 (floating-point division)
o Answer: a) 3
o Explanation: In C++, integer division truncates the decimal part, so 10 / 3
results in 3.
57. Which of the following is not a valid member function of a class in C++?
o a) Constructor
o b) Destructor
o c) Overload
o d) Accessor
o Answer: c) Overload
o Explanation: Overloading is not a member function; it is a feature that allows
multiple functions with the same name but different parameters.
58. What is the time complexity of accessing an element in a doubly linked list?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: b) O(n)
o Explanation: Accessing an element in a doubly linked list requires traversing
from the head, which takes O(n) time.
59. Which of the following is not a type of constructor in C++?
o a) Default Constructor
o b) Parameterized Constructor
o c) Copy Constructor
o d) Recursive Constructor
o Answer: d) Recursive Constructor
o Explanation: Recursive Constructor is not a valid type of constructor in C++.
60. What is the time complexity of adding an element to the end of a dynamic array?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: b) O(n)
o Explanation: Adding an element to the end of a dynamic array may require
resizing, which has a time complexity of O(n).
61. In C++, which operator is used for dynamic memory allocation?
o a) new
o b) malloc
o c) calloc
o d) realloc
o Answer: a) new
o Explanation: The new operator is used for dynamic memory allocation in
C++.
62. What is the time complexity of finding the maximum element in an unsorted
array?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: b) O(n)
o Explanation: Finding the maximum element in an unsorted array requires
scanning all elements, resulting in O(n) time complexity.
63. In Java, which method is used to compare two strings?
o a) compare()
o b) compareTo()
o c) equals()
o d) isEqual()
o Answer: b) compareTo()
o Explanation: The compareTo() method is used to compare two strings in
Java.
64. Which of the following data structures uses a FIFO order?
o a) Stack
o b) Queue
o c) Priority Queue
o d) Binary Tree
o Answer: b) Queue
o Explanation: A queue uses FIFO (First In First Out) order.
65. In C++, what is the purpose of the virtual destructor?
o a) To allow derived class destructors to be called
o b) To create a virtual base class
o c) To declare a static method
o d) To define a pure virtual function
o Answer: a) To allow derived class destructors to be called
o Explanation: A virtual destructor ensures that the destructor of the derived
class is called when an object is deleted through a base class pointer.
66. What is the purpose of the static keyword in Java?
o a) To define a class-level variable or method
o b) To define a constant value
o c) To create an abstract class
o d) To declare a variable
o Answer: a) To define a class-level variable or method
o Explanation: The static keyword is used to define class-level variables and
methods that can be accessed without creating an instance of the class.
67. Which data structure is used to implement breadth-first search (BFS)?
o a) Stack
o b) Queue
o c) Priority Queue
o d) Deque
o Answer: b) Queue
o Explanation: Breadth-first search (BFS) is implemented using a queue data
structure.
68. What is the worst-case time complexity of accessing an element in a hash table
with chaining?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: b) O(n)
o Explanation: In the worst case, when all elements hash to the same bucket,
accessing an element in a hash table with chaining can take O(n) time.
69. Which of the following methods is used to sort an array in Java?
o a) sort()
o b) order()
o c) arrange()
o d) organize()
o Answer: a) sort()
o Explanation: The sort() method is used to sort an array in Java.
70. What is the time complexity of searching for an element in a balanced binary
search tree (BST)?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: c) O(log n)
o Explanation: Searching in a balanced binary search tree (BST) has a time
complexity of O(log n).
71. In C++, what is the purpose of the friend keyword?
o a) To allow a function or class to access private members of another class
o b) To create a static method
o c) To declare a global variable
o d) To define a constant value
o Answer: a) To allow a function or class to access private members of another
class
o Explanation: The friend keyword in C++ allows a function or class to
access private and protected members of another class.
72. Which of the following is not a feature of a stack?
o a) LIFO order
o b) Push operation
o c) Pop operation
o d) FIFO order
o Answer: d) FIFO order
o Explanation: A stack operates in LIFO (Last In First Out) order, not FIFO
(First In First Out).
73. What is the time complexity of finding an element in a sorted linked list?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: b) O(n)
o Explanation: Finding an element in a sorted linked list requires traversing the
list, which takes O(n) time.
74. Which of the following is not a valid data type in Java?
o a) int
o b) float
o c) string
o d) char
o Answer: c) string
o Explanation: In Java, the string data type is represented by the String
class, not a primitive type.
75. In C++, what is the purpose of the #include directive?
o a) To include header files in a program
o b) To define a constant value
o c) To create a new class
o d) To declare a variable
o Answer: a) To include header files in a program
o Explanation: The #include directive is used to include header files in a C++
program.
76. Which of the following operations can be performed in constant time for a stack?
o a) Push
o b) Pop
o c) Peek
o d) All of the above
o Answer: d) All of the above
o Explanation: Push, pop, and peek operations can all be performed in constant
time, O(1), for a stack.
77. What is the time complexity of removing an element from the end of a doubly
linked list?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: a) O(1)
o Explanation: Removing an element from the end of a doubly linked list can
be done in constant time, O(1).
78. In Java, which method is used to convert a string to an integer?
o a) parseInt()
o b) toInt()
o c) convert()
o d) integerValue()
o Answer: a) parseInt()
o Explanation: The parseInt() method is used to convert a string to an integer
in Java.
79. Which data structure is used for implementing a LRU (Least Recently Used)
cache?
o a) Stack
o b) Queue
o c) Linked Hash Map
o d) Binary Search Tree
o Answer: c) Linked Hash Map
o Explanation: An LRU cache is often implemented using a Linked Hash Map,
which maintains insertion order and allows for efficient access and deletion.
80. What is the purpose of the this keyword in Java?
o a) To refer to the current object instance
o b) To create a new object instance
o c) To access static methods
o d) To refer to a superclass
o Answer: a) To refer to the current object instance
o Explanation: The this keyword in Java is used to refer to the current object
instance within an instance method or constructor.
81. What is the time complexity of appending an element to the end of a singly
linked list?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: b) O(n)
o Explanation: Appending an element to the end of a singly linked list requires
traversing the list to find the end, resulting in O(n) time complexity.
82. Which of the following is true about a binary search tree (BST)?
o a) The left child node's value is less than the parent's value
o b) The right child node's value is greater than the parent's value
o c) Both a and b
o d) Neither a nor b
o Answer: c) Both a and b
o Explanation: In a binary search tree (BST), the left child node's value is less
than the parent's value, and the right child node's value is greater than the
parent's value.
83. In C++, what is the purpose of the typedef keyword?
o a) To create an alias for a data type
o b) To define a new class
o c) To declare a constant value
o d) To include a header file
o Answer: a) To create an alias for a data type
o Explanation: The typedef keyword is used to create an alias for an existing
data type in C++.
84. Which of the following is not a type of polymorphism in Java?
o a) Compile-time polymorphism
o b) Runtime polymorphism
o c) Method overloading
o d) Constructor overloading
o Answer: d) Constructor overloading
o Explanation: Constructor overloading is not a type of polymorphism in Java;
it is a form of method overloading.
85. What is the purpose of the abstract keyword in Java?
o a) To define a class that cannot be instantiated
o b) To declare a static method
o c) To create a constant value
o d) To define a method that must be overridden
o Answer: a) To define a class that cannot be instantiated
o Explanation: The abstract keyword in Java is used to define a class that
cannot be instantiated directly and is meant to be extended by other classes.
86. Which data structure is used to implement depth-first search (DFS)?
o a) Queue
o b) Stack
o c) Priority Queue
o d) Deque
o Answer: b) Stack
o Explanation: Depth-first search (DFS) is typically implemented using a stack
data structure.
87. What is the time complexity of accessing an element in an array?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: a) O(1)
o Explanation: Accessing an element in an array has a constant time
complexity, O(1).
88. In C++, which operator is used for member access in a class?
o a) .
o b) ->
o c) ::
o d) &
o Answer: a) .
o Explanation: The . operator is used to access members of a class through an
object in C++.
89. Which of the following is not a feature of object-oriented programming (OOP)?
o a) Encapsulation
o b) Inheritance
o c) Polymorphism
o d) Recursion
o Answer: d) Recursion
o Explanation: Recursion is not a feature of object-oriented programming
(OOP); it is a programming technique used in various paradigms.
90. What is the purpose of the interface keyword in Java?
o a) To define a contract that implementing classes must adhere to
o b) To define a class that cannot be instantiated
o c) To create a new class
o d) To declare a variable
o Answer: a) To define a contract that implementing classes must adhere to
o Explanation: The interface keyword in Java is used to define a contract that
implementing classes must adhere to by providing implementations for its
methods.
91. Which data structure is used to implement a least recently used (LRU) cache?
o a) Array
o b) Linked List
o c) Doubly Linked List
o d) HashMap
o Answer: c) Doubly Linked List
o Explanation: An LRU cache is often implemented using a doubly linked list
combined with a hash map for efficient access and management.
92. What is the time complexity of inserting an element into a sorted linked list?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: b) O(n)
o Explanation: Inserting an element into a sorted linked list requires finding the
correct position, which takes O(n) time.
93. Which of the following is used to handle exceptions in Java?
o a) try-catch
o b) if-else
o c) switch-case
o d) for-loop
o Answer: a) try-catch
o Explanation: The try-catch block is used to handle exceptions in Java.
94. In C++, what is the purpose of the inline keyword?
o a) To suggest to the compiler to inline a function
o b) To declare a constant value
o c) To define a static method
o d) To include a header file
o Answer: a) To suggest to the compiler to inline a function
o Explanation: The inline keyword in C++ is used to suggest to the compiler
that a function should be inlined, i.e., its code should be directly inserted at
each point of function call.
95. What is the time complexity of searching for an element in a balanced binary
search tree (BST)?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: c) O(log n)
o Explanation: Searching in a balanced binary search tree (BST) has a time
complexity of O(log n).
96. Which of the following is true about the HashMap class in Java?
o a) It allows duplicate keys
o b) It maintains the order of elements
o c) It allows null keys and values
o d) It is synchronized
o Answer: c) It allows null keys and values
o Explanation: The HashMap class in Java allows null keys and values and does
not maintain the order of elements. It is also not synchronized.
97. What is the purpose of the super keyword in Java?
o a) To call the constructor of the superclass
o b) To create a static method
o c) To access the current object instance
o d) To define a constant value
o Answer: a) To call the constructor of the superclass
o Explanation: The super keyword in Java is used to call the constructor of the
superclass and to access superclass methods and variables.
98. Which of the following is not a characteristic of a stack?
o a) LIFO order
o b) Push and pop operations
o c) Can be implemented using an array or linked list
o d) FIFO order
o Answer: d) FIFO order
o Explanation: A stack operates in LIFO (Last In First Out) order, not FIFO
(First In First Out).
99. What is the time complexity of searching for an element in a hash table with
separate chaining?
o a) O(1)
o b) O(n)
o c) O(log n)
o d) O(n^2)
o Answer: b) O(n)
o Explanation: In the worst case, when all elements hash to the same bucket,
searching in a hash table with separate chaining can take O(n) time.
100. What is the purpose of the final keyword in Java? - a) To define a
constant value - b) To prevent method overriding and inheritance - c) To create an
abstract class - d) To specify a class as final - Answer: b) To prevent method
overriding and inheritance - Explanation: The final keyword in Java is used to
prevent method overriding and inheritance.