Q. If a binary search algorithm returns -1, what does it indicate?
-
A.
The element is found
-
B.
The element is not in the array
-
C.
The array is empty
-
D.
The array is sorted
Solution
A return value of -1 typically indicates that the searched element is not present in the array.
Correct Answer:
B
— The element is not in the array
Learn More →
Q. What happens if you apply binary search on an unsorted array?
-
A.
It will always find the element
-
B.
It may return incorrect results
-
C.
It will sort the array
-
D.
It will throw an error
Solution
Binary search requires a sorted array; applying it on an unsorted array may lead to incorrect results.
Correct Answer:
B
— It may return incorrect results
Learn More →
Q. What is the maximum number of comparisons needed to find an element in an array of size 16 using binary search?
Solution
The maximum number of comparisons is log2(16) = 4, but since we count the initial comparison, it is 5.
Correct Answer:
B
— 5
Learn More →
Q. Which of the following algorithms can be used to find the first occurrence of a target in a sorted array?
-
A.
Linear Search
-
B.
Binary Search
-
C.
Jump Search
-
D.
Exponential Search
Solution
Binary search can be modified to find the first occurrence of a target in a sorted array.
Correct Answer:
B
— Binary Search
Learn More →
Q. Which of the following data structures can be efficiently searched using binary search?
-
A.
Linked List
-
B.
Stack
-
C.
Queue
-
D.
Sorted Array
Solution
Binary search is efficient on sorted arrays, as it requires random access to elements.
Correct Answer:
D
— Sorted Array
Learn More →
Showing 1 to 5 of 5 (1 Pages)