Practice - MCQS-ST3
Practice - MCQS-ST3
Practice - MCQS-ST3
Answer: C. 7
5.Which traversal visits the root node after traversing the left subtree and before
traversing the right subtree?
A. Preorder
B. Inorder
C. Postorder
D. Level order
Answer: B. Inorder
6. In an inorder traversal of a binary search tree, the nodes are visited in:
A. Non-decreasing order
B. Non-increasing order
C. Random order
D. Order of insertion
Answer: D. Traversal
Answer: A. Inorder
Answer: D. Trie
Answer: A. 2^h - 1
Answer: C. A binary tree where each node's value is greater than its left subtree and less
than its right subtree
12. In a binary search tree, which traversal visits the nodes in sorted order?
A. Preorder
B. Inorder
C. Postorder
D. Level order
Answer: B. Inorder
13. What is the time complexity of searching for a value in a balanced binary search
tree?
A. O(1)
B. O(log n)
C. O(n)
D. O(n log n)
Answer: B. O(log n)
14. Which of the following operations in a binary search tree may require tree
re-balancing to maintain its properties?
A. Search
B. Insertion
C. Deletion
D. Traversal
Answer: C. Deletion
17. In a binary search tree, which operation has the worst-case time complexity?
A. Search
B. Insertion
C. Deletion
D. Traversal
Answer: D. Traversal
18. Which of the following is not a valid property of a binary search tree?
A. All nodes in the left subtree are less than the root node.
B. All nodes in the right subtree are greater than the root node.
C. All nodes in the left subtree are less than or equal to the root node.
D. All nodes in the right subtree are greater than or equal to the root node.
Answer: C. All nodes in the left subtree are less than or equal to the root node.
19. Which traversal of a binary search tree returns the nodes in descending order?
A. Preorder
B. Inorder
C. Postorder
D. Reverse Inorder
Answer: C. A data structure that maintains the maximum (or minimum) element at the
root
Answer: A. Insertion
24. Which of the following data structures is typically used to implement a heap priority
queue?
A. Array
B. Linked List
C. Stack
D. Queue
Answer: A. Array
28. Which operation is used to insert an element into a heap priority queue?
A. push()
B. pop()
C. enqueue()
D. dequeue()
Answer: A. push()
29. Which of the following heap operations requires restructuring the heap to maintain
its properties?
A. Insertion
B. Deletion
C. Searching
D. Traversal
Answer: B. Deletion
30. What is the time complexity of building a heap from an array of n elements?
A. O(n)
B. O(log n)
C. O(n log n)
D. O(n^2)
35. In an undirected graph, the number of edges is typically expressed in terms of:
A. The number of vertices
B. The number of components
C. The degree of the vertices
D. The number of connected pairs of vertices
37. Which of the following algorithms is used to find the shortest path between two vertices
in a weighted graph?
A. Depth First Search (DFS)
B. Breadth First Search (BFS)
C. Dijkstra's algorithm
D. Kruskal's algorithm
38. What is the time complexity of the depth-first search (DFS) algorithm for traversing a
graph with n vertices and m edges?
A. O(n)
B. O(m)
C. O(n + m)
D. O(n * m)
Answer: C. O(n + m)
39. Which of the following graph representations is most suitable for sparse graphs?
A. Adjacency Matrix
B. Adjacency List
C. Incidence Matrix
D. Edge List
Answer: B. A tree with the minimum number of edges that connects all vertices of the graph
42. Which algorithm is used to find the minimum spanning tree in a weighted graph?
A. Depth First Search (DFS)
B. Breadth First Search (BFS)
C. Kruskal's algorithm
D. Dijkstra's algorithm
Answer: C. Directed
Answer: A. Queue
49. What is the minimum number of edges required to form a cycle in a connected
undirected graph with n vertices?
A. n - 1
B. n
C. n + 1
D. 2
Answer: B. n
50. Which of the following graph representations is most suitable for dense graphs?
A. Adjacency Matrix
B. Adjacency List
C. Incidence Matrix
D. Edge List
52. Which of the following operations in a HashMap has constant time complexity on
average?
A. Insertion
B. Deletion
C. Search
D. Traversal
Answer: C. Search
54. What happens if you try to insert a duplicate key into a HashMap?
A. The value associated with the existing key is updated
B. An error is thrown
C. The new key-value pair is added as a separate entry
D. The operation fails and returns false
55. Which method is used to retrieve the value associated with a key in a HashMap?
A. get()
B. put()
C. remove()
D. containsKey()
Answer: A. get()
Answer: A. O(1)
Answer: A. HashMap
Answer: B. 16
60. Which data structure is internally used to implement HashMap in most programming
languages?
A. Array
B. Linked List
C. Binary Tree
D. Hash Table
Answer: A. Array
Answer: B. By chaining (using linked lists or other data structures) to store multiple values
at the same index
Answer: A. The ratio of the number of elements to the total capacity of the HashMap
63. Which of the following operations in a HashMap has a time complexity of O(1) on
average?
A. Insertion
B. Deletion
C. Search
D. Traversal
Answer: A. Insertion
64. What happens if you try to retrieve a value associated with a non-existent key in a
HashMap using the get() method?
A. An error is thrown
B. The method returns null
C. The method returns -1
D. The method returns an empty string
65. In a HashMap, what happens if the load factor exceeds a certain threshold?
A. The HashMap is resized to increase its capacity
B. The HashMap is converted into a TreeMap
C. The HashMap is converted into a LinkedHashMap
D. The HashMap becomes read-only
Answer: A. The HashMap is resized to increase its capacity
68. Which operation is efficient in a Trie for determining if a string is a prefix of any other
string?
A. Insertion
B. Deletion
C. Searching
D. Traversal
Answer: C. Searching
Answer: D. Each node has multiple characters and an array of pointers to its child nodes
71. Which of the following operations in a Trie has a time complexity of O(m), where m
is the length of the string being inserted?
A. Searching
B. Insertion
C. Deletion
D. Traversal
Answer: B. Insertion
75. Which data structure is typically used to implement the child nodes in a Trie?
A. Array
B. Linked List
C. Binary Tree
D. Hash Map
Answer: A. Array
A. push()
B. pop()
C. top()
D. dequeue()
Answer: A. push()
A. O(1)
B. O(log n)
C. O(n)
D. O(n log n)
Answer: A. O(1)
79. Which operation removes the top element from the stack?
A. push()
B. pop()
C. peek()
D. dequeue()
Answer: B. pop()
80. In a stack, which element is accessed first when performing the pop() operation?
A. The top element
B. The bottom element
C. The middle element
D. Any random element
A. enqueue()
B. dequeue()
C. push()
D. pop()
Answer: A. enqueue()
Answer: A. O(1)
84. Which operation removes an element from the front of the queue?
A. enqueue()
B. dequeue()
C. push()
D. pop()
Answer: B. dequeue()
85. In a queue, which element is accessed first when performing the dequeue()
operation?
86. How do you access the fifth element in an array named arr?
a) arr[4]
b) arr[5]
c) arr[0]
d) arr[1]
Answer: a) arr[4]
87. In C++, how can you find the number of elements in an array named numbers?
a) numbers.length()
b) sizeof(numbers)
c) numbers.size()
d) sizeof(numbers) / sizeof(numbers[0])
90. How do you find the length of a C-style string (char array) in C++?
a) strcat()
b) concat()
c) append()
d) join()
Answer: a) strcat()
92. What is the correct way to compare two C-style strings in C++?
a) strcompare()
b) strcmp()
c) compare()
d) stringCompare()
Answer: b) strcmp()
93. Which of the following statements is true about arrays in C++?
a) 2
b) 3
c) 4
d) 5
Answer: b) 3
96. What does the sizeof operator in C++ return for an array?
a) length() method
b) size() method
c) strlen() function
d) sizeOf() function
99. Which function is used to copy one C-style string into another?
a) strcpy()
b) copy()
c) strncpy()
d) stringCopy()
Answer: a) strcpy()
100. What is the purpose of the getline() function in C++ when used with strings?
102. What is the time complexity of a linear search algorithm in an array of size n?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: b) O(n)
103. If an algorithm has a time complexity of O(log n), what type of algorithm is it likely
to be?
a) Linear algorithm
b) Quadratic algorithm
c) Exponential algorithm
d) Logarithmic algorithm
105. What is the space complexity of a recursive algorithm with a depth of recursion log
n?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: c) O(log n)
a) O(1)
b) O(n)
c) O(n^2)
d) O(log n)
Answer: c) O(n^2)
107. In binary search, what is the key requirement for the array?
a) It must be sorted in descending order.
b) It must be sorted in ascending order.
c) It can be in any order.
d) It must have only unique elements.
108. What is the time complexity of binary search on a unsorted array of size n?
a) O(1)
b) O(log n)
c) O(n)
d) not possible
109. If the target element is not present in the array during binary search, what does the
algorithm return?
a) -1
b) 0
c) The index of the last element
d) An error message
Answer: a) -1
a) Simplicity of implementation
b) Stack overflow for large arrays
c) Efficient for unsorted arrays
d) Suitable for dynamic arrays only
a) Linear Search
b) Bubble Sort
c) Quick Sort
d) Merge Sort
113. In binary search, what is the purpose of checking the middle element against the
target?
116. In bitwise AND operation (&), what is the result if both bits are 1?
a) 0
b) 1
c) -1
d) No change
Answer: b) 1
a) 8
b) 4
c) 2
d) 1
Answer: a) 8
a) AND (&)
b) OR (|)
c) XOR (^)
d) NOT (~)
Answer: b) OR (|)
119. In bitwise XOR operation (^), what is the result if both bits are the same?
a) 0
b) 1
c) -1
d) No change
Answer: a) 0
a) Left shift
b) Right shift
c) Bitwise AND
d) Bitwise OR
a) AND (&)
b) OR (|)
c) XOR (^)
d) NOT (~)
a) 0
b) 1
c) 3
d) 5
Answer: c) 3
a) A search algorithm
b) An optimization technique
c) A technique to explore all possible solutions
d) A data structure
a) Linear search
b) subset problems
c) Sudoku solving
d) Binary search
128. What does the term "backtrack" refer to in the context of backtracking algorithms?
130. Which data structure is commonly used for keeping track of choices in
backtracking?
a) Stack
b) Queue
c) Linked list
d) Array
Answer: a) Stack
133. If an algorithm has a time complexity of O(1), what can be said about its efficiency?
a) It is very efficient.
b) It is moderately efficient.
c) It is less efficient.
d) It depends on other factors.
Answer: a) It is very efficient.
134. Which of the following statements is true about the relationship between O(f(n))
and Θ(f(n))?
}
a) 10
b) Memory address of x
c) Compilation error
d) Garbage value
Answer: a) 10
Answer: b) 8 bytes
a) It deallocates memory
b) It creates a new variable
c) It dynamically allocates memory on the heap
d) It is used for pointer arithmetic
Answer: c) It dynamically allocates memory on the heap