Q. In a binary search tree, how does binary search help in finding an element?
-
A.
By traversing all nodes
-
B.
By comparing with the root and deciding left or right
-
C.
By using a queue
-
D.
By using a stack
Solution
In a binary search tree, binary search helps by comparing the target with the root and deciding whether to go left or right based on the value.
Correct Answer:
B
— By comparing with the root and deciding left or right
Learn More →
Q. What happens if you apply binary search on an array that is not sorted?
-
A.
It will find the element correctly
-
B.
It will not find the element
-
C.
It may return an incorrect index
-
D.
It will throw an error
Solution
Binary search assumes the array is sorted; if it is not, it may return an incorrect index.
Correct Answer:
C
— It may return an incorrect index
Learn More →
Q. What is the average case time complexity of binary search?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The average case time complexity of binary search is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the main requirement for using binary search?
-
A.
The array must be unsorted
-
B.
The array must be sorted
-
C.
The array must contain unique elements
-
D.
The array must be of fixed size
Solution
Binary search can only be applied to a sorted array.
Correct Answer:
B
— The array must be sorted
Learn More →
Q. Which of the following data structures can be used to implement binary search efficiently?
-
A.
Linked List
-
B.
Array
-
C.
Stack
-
D.
Queue
Solution
Binary search is most efficiently implemented on an array due to its random access capabilities.
Correct Answer:
B
— Array
Learn More →
Showing 1 to 5 of 5 (1 Pages)