Q. If a binary search is performed on an array of size 16, how many comparisons will be made in the worst case?
Solution
In the worst case, binary search will make log2(16) = 4 comparisons.
Correct Answer:
D
— 5
Learn More →
Q. What happens if the target value is not present in the array during a binary search?
-
A.
The search returns the index of the closest value
-
B.
The search returns -1
-
C.
The search continues indefinitely
-
D.
The search throws an error
Solution
If the target value is not found, binary search typically returns -1 to indicate absence.
Correct Answer:
B
— The search returns -1
Learn More →
Q. What is the space complexity of binary search?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(1)
-
D.
O(n log n)
Solution
Binary search has a space complexity of O(1) when implemented iteratively.
Correct Answer:
C
— O(1)
Learn More →
Q. Which of the following best describes the process of binary search?
-
A.
Iteratively checking each element
-
B.
Dividing the array into halves
-
C.
Sorting the array first
-
D.
Using a hash table
Solution
Binary search works by dividing the array into halves to locate the target value.
Correct Answer:
B
— Dividing the array into halves
Learn More →
Q. Which of the following data structures can binary search be applied to?
-
A.
Linked lists
-
B.
Binary trees
-
C.
Sorted arrays
-
D.
Hash tables
Solution
Binary search is specifically designed for sorted arrays.
Correct Answer:
C
— Sorted arrays
Learn More →
Q. Which of the following is a common application of binary search?
-
A.
Finding the minimum element in an array
-
B.
Finding an element in a sorted array
-
C.
Sorting an array
-
D.
Reversing an array
Solution
Binary search is commonly used to find an element in a sorted array.
Correct Answer:
B
— Finding an element in a sorted array
Learn More →
Showing 1 to 6 of 6 (1 Pages)