A developer needs to find if any duplicate patient IDs exist in a very large list containing millions of encounter records. They are considering two approaches:
Approach A: Use a nested loop. For each ID in the list, iterate through the rest of the list to check for a match.
Approach B: Iterate through the list once, adding each ID to a Hash Set. If an ID is already in the set when attempting to add it, a duplicate has been found.
Which statement best describes the performance of these two approaches as the list size grows?
-
A
Both approaches have roughly the same efficiency.
-
B
Approach A will be significantly more efficient than Approach B.
-
C
The efficiency difference is minor and depends on the number of duplicates.
-
D
Approach B will be significantly more efficient than Approach A.