Hashing

Concept shape

Core
key
bucket 0
bucket 1
bucket 2
bucket 3
Definition

A hash map stores key-value pairs and gives fast average lookup by key.

Step 1 / 5
Concept shape
Current lesson

Hash Maps Lab

Hashing Core

Hash Maps

Welcome to the Hash Maps concept lab. A hash map stores key-value pairs and gives fast average lookup by key. The must know points are: Average lookup is O(1). Keys must be hashable. Great for frequency and lookup problems. The common operations are: get average O(1), set average O(1), delete average O(1), contains average O(1). The complexity shape is Average O(1), worst O(n). Watch out for these pitfalls: Assuming iteration order unless guaranteed. Forgetting collision worst cases. Using mutable objects as keys incorrectly. Related algorithms include Two Sum, Prefix Sum with Hash Map.

Concept details

A hash map stores key-value pairs and gives fast average lookup by key.

Must know

  • Average lookup is O(1).
  • Keys must be hashable.
  • Great for frequency and lookup problems.

Complexity

Average O(1), worst O(n)

Open deeper visual structure lesson
1.0x