Lesson 5.1
Sets and Maps as Abstractions
A set stores membership without duplicates; a map stores key-to-value associations. Both are specifications, implementable by hashing or by a tree.
Lookup by key instead of by position. Hashing is the first place where average and worst case diverge sharply, which makes stating the case a required part of every answer.
Lesson 5.1
A set stores membership without duplicates; a map stores key-to-value associations. Both are specifications, implementable by hashing or by a tree.
Lesson 5.2
A hash function maps a key to a bucket. A good one spreads keys evenly, which is exactly the assumption behind constant average lookup.
Lesson 5.3
Chaining hangs a secondary structure off each bucket; open addressing probes for another slot. Linear probing suffers primary clustering, where occupied runs lengthen future probes.
Lesson 5.4
Load factor is entries divided by buckets, and rising load predicts more collisions. Implementations resize past a threshold, rehashing every key.
Work through questions with a tutor and get help with the steps you find difficult.
Get help with this topic