Q. If an array contains 32 elements, how many iterations will binary search take in the worst case?
Show solution
Solution
For an array of 32 elements, the worst-case number of iterations is log2(32) = 5.
Correct Answer:
A
— 4
Learn More →
Q. In which scenario would binary search not be applicable?
A.
Searching in a sorted array
B.
Searching in a linked list
C.
Searching in a sorted linked list
D.
Searching in a sorted array with duplicates
Show solution
Solution
Binary search is not applicable for linked lists because it requires random access to elements, which linked lists do not provide.
Correct Answer:
B
— Searching in a linked list
Learn More →
Q. What is the primary 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
Show solution
Solution
The primary advantage of binary search is its better time complexity of O(log n) compared to linear search's O(n).
Correct Answer:
C
— It has a better time complexity
Learn More →
Q. What is the time complexity of binary search in the average case?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
In the average case, binary search divides the search space in half with each iteration, leading to a time complexity of O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of binary search in the best case scenario?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
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:
A
— O(1)
Learn More →
Q. What is the time complexity of binary search in the worst case scenario?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
In the worst case, binary search will continue to halve the search space until it finds the target or concludes it is not present, resulting in O(log n) time complexity.
Correct Answer:
B
— O(log n)
Learn More →
Q. Which of the following is a key characteristic of binary search?
A.
It can find the first occurrence of an element
B.
It can find the last occurrence of an element
C.
It requires a sorted array
D.
It can work on any data structure
Show solution
Solution
A key characteristic of binary search is that it requires a sorted array to function correctly.
Correct Answer:
C
— It requires a sorted array
Learn More →
Showing 1 to 7 of 7 (1 Pages)