CompTIA Tech+ (FC0-U71)Software Development ConceptsMedium

A developer is writing a program that needs to store a collection of unique email addresses. The program should efficiently add new addresses and quickly check if an address already exists, without allowing duplicates. Which data structure is best suited for this task?

  1. AStack
  2. BSet
  3. CQueue
  4. DList (Array)
Show answer & explanation

Correct answer: B. Set

A Set is a data structure specifically designed to store unique elements. It inherently prevents duplicates and typically provides efficient operations for adding elements and checking for existence (membership testing), making it ideal for managing unique email addresses.

Why the other options are wrong

  • A. A Stack is a LIFO structure, not designed for ensuring uniqueness or efficient membership testing.
  • C. A Queue is a FIFO structure, not designed for ensuring uniqueness or efficient membership testing.
  • D. A List (or Array) can store duplicates and checking for existence requires iterating through elements, which is less efficient for large collections.

Set Data Structure

A Set is an abstract data type that can store unique, unordered elements. It provides efficient operations for adding elements, removing elements, and checking for membership.

  • Does not allow duplicate elements.
  • Elements are typically unordered.
  • Optimized for quick membership testing (checking if an element exists).

Memory trick: Sets are like exclusive clubs, no duplicates allowed.

More Software Development Concepts questions