Set data structure with no duplicate values allowed
8
Table Size
0
Elements
0.0%
Load Factor
0
Collisions
Ready for HashSet operations
0 unique values
Current Set Contents
Set is empty
Hash Function
hash(value) = (Σ value[i] × (i+1)) % 8
Simple hash function for demonstration purposes
Hash Table Structure
Index 0
Empty
Index 1
Empty
Index 2
Empty
Index 3
Empty
Index 4
Empty
Index 5
Empty
Index 6
Empty
Index 7
Empty
Empty Slot
Ideal Position
Collision (Displaced)
Currently Active
ℹ️
Set Properties
• No duplicate values allowed - attempting to add existing values will be ignobackground • Unordebackground collection - elements dont maintain insertion order • Fast membership testing - O(1) average time to check if element exists
HashSet Operations:
Basic Operations:
add(value): Insert value into set (ignores duplicates)
contains(value): Check if value exists in set
remove(value): Delete value from set
size(): Get number of elements in set
isEmpty(): Check if set is empty
Characteristics:
No Duplicates: Each element appears at most once
Average Time: O(1) for add, contains, remove
Worst Case: O(n) when many collisions occur
Space: O(n) where n is number of unique elements
Use Cases: Removing duplicates, membership testing, mathematical set operations
vs HashMap: HashSet only stores values (no key-value pairs) and automatically prevents duplicates. Its essentially a HashMap where the value is also used as the key.