CMSC 132. Sets, Maps, Hashing
Set data structures - answer A set is a data structure in which there is no relationship
between the elements being stored
Set- Just a collection of elements
Map- Associates values with keys
Hash table
Sets - answer- No duplicates
- No ordering of elements
Be able to add and delete elements, and test whether elements are in a set quickly
(without iterating through all of the set's elements)
Java library (Collection) set classes – answer HashSet
- Elements must implement the hash Code() method
- Implemented using hashing
LinkedHashSet
- LinkedHashSet is a HashSet supporting ordering of elements
- The elements of a LinkedHashSet will be iterated over in the order that they were
inserted
TreeSet
- Elements must be comparable (either implement Comparable or provide a
Comparator)
- The elements of a TreeSet will be iterated over in increasing (sorted) order
Finding set elements - answerFinding a matching element is based on the equals()
method
Some of Java's Set<E> Interface Methods - answerboolean add(E element)
boolean contains(Object o)
boolean remove(Object element)
boolean isEmpty()
int size()
Set data structures - answer A set is a data structure in which there is no relationship
between the elements being stored
Set- Just a collection of elements
Map- Associates values with keys
Hash table
Sets - answer- No duplicates
- No ordering of elements
Be able to add and delete elements, and test whether elements are in a set quickly
(without iterating through all of the set's elements)
Java library (Collection) set classes – answer HashSet
- Elements must implement the hash Code() method
- Implemented using hashing
LinkedHashSet
- LinkedHashSet is a HashSet supporting ordering of elements
- The elements of a LinkedHashSet will be iterated over in the order that they were
inserted
TreeSet
- Elements must be comparable (either implement Comparable or provide a
Comparator)
- The elements of a TreeSet will be iterated over in increasing (sorted) order
Finding set elements - answerFinding a matching element is based on the equals()
method
Some of Java's Set<E> Interface Methods - answerboolean add(E element)
boolean contains(Object o)
boolean remove(Object element)
boolean isEmpty()
int size()