Intermediate Data Structures & Algorithms
Q76 / 100

What is the main advantage of using a hash set to detect duplicates in a collection compared to sorting first?

Correct! Well done.

Incorrect.

The correct answer is C) A hash set lets you check and record each element in O(1) average time during a single pass, achieving O(n) average time versus the O(n log n) needed to sort first

C

Correct Answer

A hash set lets you check and record each element in O(1) average time during a single pass, achieving O(n) average time versus the O(n log n) needed to sort first

Explanation

Inserting into a hash set and checking membership both take O(1) average time, so scanning the collection once and tracking seen elements detects duplicates in O(n) average time, which is faster than the O(n log n) cost of sorting the data first.

Progress
76/100