Free Online Flashcard Deck

08. Searching Algorithms Free Online FlashCards

Study 08. Searching Algorithms with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is linear search?

Back

Linear search checks elements one at a time until it finds the target or reaches the end. It does not require sorted data.

02
Front

What is binary search?

Back

Binary search repeatedly compares the target with the middle element and discards the half where the target cannot occur.

03
Front

Does linear search require sorted data?

Back

No. Linear search works whether or not the collection is sorted.

04
Front

What ordering requirement does binary search have?

Back

Yes. Binary search requires the data to be sorted according to the same ordering used for comparisons.

05
Front

What are linear search’s best- and worst-case times?

Back

Linear search has best-case time O(1), when the first element matches, and worst-case time O(n), when the target is last or absent.

06
Front

What are binary search’s best- and worst-case times?

Back

With efficient indexed access, binary search has best-case time O(1) and worst-case time O(log n).

07
Front

What invariant does binary search maintain?

Back

Before each binary-search step, if the target exists, it must lie between low and high. Updates remove impossible positions while preserving that possibility.

08
Front

How does binary search handle target < middle value?

Back

For an ascending list, if the target is smaller than the middle value, set high to middle - 1 and search the lower half.

09
Front

How does binary search handle target > middle value?

Back

For an ascending list, if the target is larger than the middle value, set low to middle + 1 and search the upper half.

10
Front

Why use low + (high - low) // 2 for the midpoint?

Back

The expression low + (high - low) // 2 can avoid integer overflow that may occur with (low + high) // 2 when index values are very large.

11
Front

How can binary search find the first or last duplicate?

Back

Ordinary binary search may return any matching occurrence. To find the first, record a match and continue in the lower half; to find the last, continue in the upper half.

12
Front

Which boundary cases should binary search handle?

Back

A robust binary search must handle an empty list, targets outside the data range, matches at either boundary, and absent targets.