Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

Which data structure generally offers expected O(1)O(1) lookup for exact-key searches but does not naturally support ordered queries such as “find the smallest value greater than xx”?

  1. A

    Binary search

  2. B

    A hash table

  3. C

    Linear search

  4. D

    A balanced search tree

02
Choose one
1 point

Which collection is the most suitable for a straightforward iterative binary search because its middle element can be accessed directly by index?

  1. A

    An array

  2. B

    A singly linked list

  3. C

    An unordered set without indexing

  4. D

    A stream that can only be read once

03
Choose one
1 point

Why is low+(high−low)//2low + (high - low) // 2 preferred to (low+high)//2(low + high) // 2 in some fixed-width integer languages?

  1. A

    It always produces a floating-point midpoint.

  2. B

    It searches both halves simultaneously.

  3. C

    It avoids adding the two potentially large indices directly.

  4. D

    It guarantees that the target is present.

04
Choose all
1 point

Which two conditions are required for binary search to provide its usual efficient behavior?

  1. A

    The collection is sorted according to the search comparison rule.

  2. B

    The collection must contain distinct values.

  3. C

    The middle element can be accessed efficiently.

  4. D

    The collection must be stored in a linked list.

05
Choose all
1 point

Which two statements correctly describe the trade-offs involved in sorting data before using binary search?

  1. A

    Sorting cost must be included when analyzing the complete process.

  2. B

    Maintaining sorted order may increase insertion and deletion costs.

  3. C

    Binary search remains valid on unsorted data after one failed comparison.

  4. D

    Sorting always makes a single search faster overall.

06
True or false
1 point

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)O(n).

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: Recursive binary search typically uses more extra space than iterative binary search because of its call stack.

  1. A

    True

  2. B

    False

08
Written response
1 point

In a sorted collection containing duplicate target values, what result does a modified binary search return when it continues left after each match?

09
Written response
1 point

For approximately one million sorted array elements, about how many halving steps does binary search need in the worst case?

10
Fill in the blank
1 point

To find the first occurrence of a target after a match is found, the algorithm continues searching to the .

11
Fill in the blank
1 point

Binary search requires the collection to be arranged in according to the comparison rule used by the search.

12
Open ended
1 point

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.

13
Choose one
1 point

Which statement is the loop invariant used to justify the correctness of iterative binary search?

  1. A

    Every element outside the range has already been returned as a match.

  2. B

    If the target occurs, it occurs within the inclusive range from low through high.

  3. C

    The target is equally likely to occur at every index in the range.

  4. D

    The range always contains exactly half of the original array.

14
Choose one
1 point

Why can a straightforward binary-search strategy be inefficient on a sorted linked list?

  1. A

    Repeatedly locating middle nodes requires traversal.

  2. B

    Linked lists cannot contain sorted values.

  3. C

    Linear search is impossible on linked lists.

  4. D

    A linked list always changes its values during a search.

15
Choose one
1 point

Why is the midpoint expression low + (high - low) // 2 preferred to (low + high) // 2 in some implementations of binary search?

  1. A

    It guarantees that the target is at the exact middle of the array.

  2. B

    It reduces the risk of integer overflow when computing the midpoint.

  3. C

    It allows binary search to work on unsorted data.

  4. D

    It makes linked-list access constant time.

16
Choose one
1 point

Which task is not naturally supported by a hash table's expected constant-time exact-key lookup?

  1. A

    Finding whether an exact key is present

  2. B

    Returning the record associated with an exact key

  3. C

    Finding the smallest stored value greater than a given value

  4. D

    Testing whether two exact keys are equal

17
Choose one
1 point

A linear search examines every element and reaches the end without finding the target. What conclusion is justified?

  1. A

    The target must be at the first position.

  2. B

    The collection must have been sorted first.

  3. C

    Every position has been checked and the target is absent.

  4. D

    The target is present but has no associated record.

18
True or false
1 point

True or false: For binary search, an iterative implementation typically uses constant extra space, whereas a recursive implementation typically uses logarithmic call-stack space.

  1. A

    True

  2. B

    False

19
Written response
1 point

A sorted array contains approximately one million elements. In the worst case, about how many halving steps does binary search need?

20
Written response
1 point

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?