Module 05 of 12

Hash Tables & Sets

Lessons

About This Module

A hash table answers one question extremely well: "have I seen this before, and what goes with it?" It runs each key through a hash function to get an array position, so lookup, insert and delete take constant time on average, no matter how many items are stored. It is the structure behind Python dictionaries, JavaScript objects and maps, and every language's set type.

This module starts with how a hash table works: what a hash function does and why it gives fast lookups. It then covers the unavoidable problem of collisions, when two keys land in the same slot, and the two standard fixes, chaining and open addressing with probing.

The second half is about using them. Two Sum shows how storing what you have already seen removes a nested loop, and frequency counting with a Valid Anagram check shows the other everyday use: counting things. A set is the same idea when you only need to know whether something is present. Watch the lessons in order, then continue on to Recursion & Backtracking.

Lessons

4 videos
01

The Hash Table: O(1) Lookups, Hashing, and Collisions Explained

The data structure itself before any problems: how a hash table gets O(1) average lookups, what a hash function actually does, and how collisions come up.

02

Collision Handling in Hash Table

Two ways to resolve collisions, separate chaining and linear probing (open addressing), explained and implemented in Python.

03

Two Sum Problem

Explains the Two Sum problem, the basic approach first, then the improved HashMap solution that finds the pair in one pass.

04

Valid Anagram: Hash Map Frequency Count Explained Visually

LeetCode 242 solved with frequency counting: how to build and compare character counts with a hash map, shown with clean visuals.