A non-ordered collection that stores unique values. One can perform mathematical set operations such as union or intersection between multiple sets.
| Pros | Cons |
|---|---|
| Provides a way to keep track of unique elements | There is no insertion or sort order |
| No indexing |
| Operation | Set (Hash-based) | Set (BST-based) |
|---|---|---|
| Delete | Worst: O(n)
Avg: O(1) |
Worst: O(n)
Avg: O(log n) |
| Insert | Worst: O(n)
Avg: O(1) |
Worst: O(n)
Avg: O(log n) |
| Search | Worst: O(n)
Avg: O(1) |
Worst: O(n)
Avg: O(log n) |