Q. In a binary search, if the target value is not found, what will be the return value?
-
A.
-1
-
B.
0
-
C.
null
-
D.
the index of the closest value
Solution
Typically, binary search returns -1 to indicate that the target value is not present in the array.
Correct Answer:
A
— -1
Learn More →
Q. In which of the following applications is binary search commonly used?
-
A.
Finding the maximum element in an array
-
B.
Searching for a word in a dictionary
-
C.
Sorting an array
-
D.
Finding the minimum element in a tree
Solution
Binary search is commonly used for searching for a word in a dictionary, as dictionaries are typically sorted.
Correct Answer:
B
— Searching for a word in a dictionary
Learn More →
Q. What is the result of performing a binary search on the array [2, 4, 6, 8, 10] for the value 5?
-
A.
5
-
B.
4
-
C.
6
-
D.
Not found
Solution
The value 5 is not present in the array, so the result of the binary search would be 'Not found'.
Correct Answer:
D
— Not found
Learn More →
Q. Which of the following is a key requirement for implementing binary search?
-
A.
The array must be sorted
-
B.
The array must be of even length
-
C.
The array must contain integers only
-
D.
The array must be in ascending order
Solution
The key requirement for implementing binary search is that the array must be sorted.
Correct Answer:
A
— The array must be sorted
Learn More →
Showing 1 to 4 of 4 (1 Pages)