Q. How does binary search determine the next interval to search?
-
A.
By comparing the target with the middle element
-
B.
By checking the first and last elements
-
C.
By using a hash table
-
D.
By traversing the entire array
Solution
Binary search determines the next interval by comparing the target with the middle element and deciding which half to continue searching.
Correct Answer:
A
— By comparing the target with the middle element
Learn More →
Q. In which of the following scenarios is binary search most beneficial?
-
A.
Finding an element in a large sorted array
-
B.
Finding the maximum element in an unsorted array
-
C.
Inserting an element in a linked list
-
D.
Sorting an array
Solution
Binary search is most beneficial for finding an element in a large sorted array due to its O(log n) time complexity.
Correct Answer:
A
— Finding an element in a large sorted array
Learn More →
Q. What happens if the target value is not present in the sorted array during a binary search?
-
A.
The search will return the index of the closest value
-
B.
The search will return -1
-
C.
The search will enter an infinite loop
-
D.
The search will throw an error
Solution
If the target value is not present, binary search will return -1 or a similar indicator of absence.
Correct Answer:
B
— The search will return -1
Learn More →
Q. What is a real-world application of binary search?
-
A.
Finding a word in a dictionary
-
B.
Sorting a list of names
-
C.
Inserting data into a database
-
D.
Traversing a tree structure
Solution
A real-world application of binary search is finding a word in a dictionary, where the words are sorted alphabetically.
Correct Answer:
A
— Finding a word in a dictionary
Learn More →
Q. What is the primary condition for using binary search on a dataset?
-
A.
The dataset must be sorted
-
B.
The dataset must be unsorted
-
C.
The dataset must be of fixed size
-
D.
The dataset must contain unique elements
Solution
Binary search requires the dataset to be sorted in order to efficiently locate the target value.
Correct Answer:
A
— The dataset must be sorted
Learn More →
Q. What is the time complexity of binary search?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
The time complexity of binary search is O(log n) because it divides the search interval in half with each step.
Correct Answer:
B
— O(log n)
Learn More →
Q. Which of the following is NOT a requirement for binary search?
-
A.
The dataset must be sorted
-
B.
The dataset must be in an array format
-
C.
The dataset must allow random access
-
D.
The dataset must be of finite size
Solution
Binary search does not require the dataset to be in an array format; it can also be applied to other structures that allow random access.
Correct Answer:
B
— The dataset must be in an array format
Learn More →
Showing 1 to 7 of 7 (1 Pages)