| Operation | Best | Average | Worst |
|---|---|---|---|
| Add | O(1) | O(1) | O(n) |
| Contains | O(1) | O(1) | O(n) |
| Remove | O(1) | O(1) | O(n) |
| Component | Space |
|---|---|
| Set Storage | O(n) |
A Set is an abstract data structure that represents an unordered collection of unique elements.
Key Characteristics:
Uniqueness Property: If an element already exists, adding it again does not create a duplicate.
Abstract Structure: A Set is conceptual; implementations include Hash Sets (fast lookup) and Tree Sets (sorted).
| Aspect | Set | Hash Set | Tree Set |
|---|---|---|---|
| Ordering | Unordered | Unordered | Sorted |
| Add Time | O(1)-O(n) | O(1) avg | O(log n) |
| Contains Time | O(1)-O(n) | O(1) avg | O(log n) |
| Remove Time | O(1)-O(n) | O(1) avg | O(log n) |
| Implementation | Abstract | Hash Table | Binary Tree |
| Memory | Minimal | Moderate | Higher |
| Best For | Concept | Fast lookups | Sorted data |