Q. If a binary search is performed on an array of size 16, how many comparisons will it take in the worst case?
Solution
In the worst case, binary search will take log2(16) = 4 comparisons, but since we start counting from 0, it will take 5 comparisons.
Correct Answer:
D
— 5
Learn More →
Q. In which scenario is binary search NOT applicable?
-
A.
Finding an element in a sorted array
-
B.
Finding the square root of a number
-
C.
Finding an element in an unsorted array
-
D.
Finding the maximum element in a sorted array
Solution
Binary search cannot be applied to an unsorted array as it relies on the order of elements.
Correct Answer:
C
— Finding an element in an unsorted array
Learn More →
Q. What is the best-case time complexity of binary search?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(1)
-
D.
O(n log n)
Solution
In the best case, the target element is found at the middle of the array, resulting in a time complexity of O(1).
Correct Answer:
C
— O(1)
Learn More →
Q. What is the main advantage of binary search over linear search?
-
A.
It is easier to implement
-
B.
It works on unsorted arrays
-
C.
It has a better time complexity
-
D.
It requires less memory
Solution
Binary search has a time complexity of O(log n), which is significantly better than the O(n) of linear search.
Correct Answer:
C
— It has a better time complexity
Learn More →
Q. What modification is needed to perform binary search on a rotated sorted array?
-
A.
No modification needed
-
B.
Use linear search
-
C.
Modify the mid-point calculation
-
D.
Use a different algorithm
Solution
To perform binary search on a rotated sorted array, the mid-point calculation must be adjusted to account for the rotation.
Correct Answer:
C
— Modify the mid-point calculation
Learn More →
Q. Which data structure is most suitable for implementing binary search?
-
A.
Linked List
-
B.
Array
-
C.
Stack
-
D.
Queue
Solution
Binary search is most efficiently implemented on arrays due to their random access capabilities.
Correct Answer:
B
— Array
Learn More →
Q. Which of the following applications can utilize binary search?
-
A.
Finding the first occurrence of a number
-
B.
Finding the last occurrence of a number
-
C.
Finding the square root of a number
-
D.
All of the above
Solution
Binary search can be adapted for various applications, including finding occurrences and calculating square roots.
Correct Answer:
D
— All of the above
Learn More →
Q. Which of the following is a prerequisite for using binary search?
-
A.
The array must be sorted
-
B.
The array must be unsorted
-
C.
The array must contain unique elements
-
D.
The array must be of fixed size
Solution
Binary search requires the array to be sorted in order to function correctly.
Correct Answer:
A
— The array must be sorted
Learn More →
Q. Which of the following statements about binary search is true?
-
A.
It can be used on linked lists
-
B.
It requires the array to be sorted
-
C.
It is always faster than linear search
-
D.
It can find multiple occurrences of an element
Solution
Binary search requires the array to be sorted to function correctly.
Correct Answer:
B
— It requires the array to be sorted
Learn More →
Showing 1 to 9 of 9 (1 Pages)