Link
Hashing
Applying properties of hash functions and hash tables.
Kevin Lin, with thanks to many others.
1

Inserting and Resizing
Draw the hash table after inserting 5. As part of this insertion, resize to M=8 buckets.
The default hashCode for integers returns the value of the integer.
2
Q
8
25
10
18
15
0
1
2
3
4
5
6
7
0
1
2
3
Q1: Draw the hash table after inserting 5. As part of this insertion, resize to M=8 buckets.

Inserting and Resizing
Draw the hash table after inserting 5. As part of this insertion, resize to M=8 buckets.
The default hashCode for integers returns the value of the integer.
3
A
8
25
10
18
15
0
1
2
3
4
5
6
7
0
1
2
3

4
Algorithms (Sedgewick, Wayne/Pearson)
public int hashCode() {
    return 17;
}
Does this hash function always, sometimes, or never work?
Q
Q1: Does this hash function always, sometimes, or never work?

Does this hash function always, sometimes, or never work?
5
A

What is the most significant problem with the Circle class?
6
public class Circle {
    private HashSet<Member> members;
    private String teamName;
    public int hashCode() {
        return Objects.hash(members, teamName);
    }
    public boolean equals(Object o) {
        Circle other = (Circle) o;
        return this.members.equals(other.members)
            && this.teamName.equals(other.teamName);
    }
    public void addMember(Member newMember) {
        members.add(newMember);
    }
}
Q
Q1: What is the most significant problem with the Circle class?

What is the most significant problem with the Circle class?
7
A

Bucket Data Structure
Suppose we represent hash table buckets with LLRB trees instead of linked lists.
Give a tight asymptotic runtime bound in terms of N, the total size of the hash set, for:
add

contains

remove

8
Q
?: What are the asymptotic runtime bounds for these operations in a regular hash set?




Q1: Give a tight asymptotic runtime bound in terms of N, the total size of the hash set, for:

add




contains




remove

Bucket Data Structure
Suppose we represent hash table buckets with LLRB trees instead of linked lists.
Give a tight asymptotic runtime bound in terms of N, the total size of the hash table, for:
add

contains

remove

9
A