Which data structure generally offers expected lookup for exact-key searches but does not naturally support ordered queries such as “find the smallest value greater than ”?
8 Searching Algorithms Online Quiz Questions
Use this free practice quiz with 20 questions to review 8 Searching Algorithms, test your knowledge, and prepare for your next test or exam.
Which collection is the most suitable for a straightforward iterative binary search because its middle element can be accessed directly by index?
- A
An array
- B
A singly linked list
- C
An unordered set without indexing
- D
A stream that can only be read once
Why is low+(high−low)//2 preferred to (low+high)//2 in some fixed-width integer languages?
- A
It always produces a floating-point midpoint.
- B
It searches both halves simultaneously.
- C
It avoids adding the two potentially large indices directly.
- D
It guarantees that the target is present.
Which two conditions are required for binary search to provide its usual efficient behavior?
- A
The collection is sorted according to the search comparison rule.
- B
The collection must contain distinct values.
- C
The middle element can be accessed efficiently.
- D
The collection must be stored in a linked list.
Which two statements correctly describe the trade-offs involved in sorting data before using binary search?
- A
Sorting cost must be included when analyzing the complete process.
- B
Maintaining sorted order may increase insertion and deletion costs.
- C
Binary search remains valid on unsorted data after one failed comparison.
- D
Sorting always makes a single search faster overall.
True or false: Under the usual assumption that a target is equally likely to occur at any position, linear search has average-case time O(n).
- A
True
- B
False
True or false: Recursive binary search typically uses more extra space than iterative binary search because of its call stack.
- A
True
- B
False
In a sorted collection containing duplicate target values, what result does a modified binary search return when it continues left after each match?
For approximately one million sorted array elements, about how many halving steps does binary search need in the worst case?
To find the first occurrence of a target after a match is found, the algorithm continues searching to the .
Binary search requires the collection to be arranged in according to the comparison rule used by the search.
A program repeatedly searches a small collection whose elements change frequently, and the collection is not kept sorted. Which search strategy should be chosen, and why? Explain the relevant search and maintenance costs.
Which statement is the loop invariant used to justify the correctness of iterative binary search?
- A
Every element outside the range has already been returned as a match.
- B
If the target occurs, it occurs within the inclusive range from low through high.
- C
The target is equally likely to occur at every index in the range.
- D
The range always contains exactly half of the original array.
Why can a straightforward binary-search strategy be inefficient on a sorted linked list?
- A
Repeatedly locating middle nodes requires traversal.
- B
Linked lists cannot contain sorted values.
- C
Linear search is impossible on linked lists.
- D
A linked list always changes its values during a search.
Why is the midpoint expression low + (high - low) // 2 preferred to (low + high) // 2 in some implementations of binary search?
- A
It guarantees that the target is at the exact middle of the array.
- B
It reduces the risk of integer overflow when computing the midpoint.
- C
It allows binary search to work on unsorted data.
- D
It makes linked-list access constant time.
Which task is not naturally supported by a hash table's expected constant-time exact-key lookup?
- A
Finding whether an exact key is present
- B
Returning the record associated with an exact key
- C
Finding the smallest stored value greater than a given value
- D
Testing whether two exact keys are equal
A linear search examines every element and reaches the end without finding the target. What conclusion is justified?
- A
The target must be at the first position.
- B
The collection must have been sorted first.
- C
Every position has been checked and the target is absent.
- D
The target is present but has no associated record.
True or false: For binary search, an iterative implementation typically uses constant extra space, whereas a recursive implementation typically uses logarithmic call-stack space.
- A
True
- B
False
A sorted array contains approximately one million elements. In the worst case, about how many halving steps does binary search need?
What is the standard algorithmic term for a property that remains true before and after every iteration and is used to prove a search algorithm correct?