Skip to main content
← Data Structures & Algorithms Study Guide

Unit 4 · Heavy

Hash Tables, Heaps, and Priority Structures

Two structures that trade ordering for speed. Hashing gives constant average lookup by abandoning order entirely; a heap keeps only enough order to expose the extreme element.

Topics in this unit

1

Hash Tables

Know

Constant average lookup depends on a hash function spreading keys evenly. With every key colliding the structure degrades to a list.

Apply

Use hashing when membership or lookup by key dominates and order does not matter.

Watch out

Quoting constant time without the even-distribution assumption, which makes the claim unfalsifiable.

2

Collisions and Load Factor

Know

Chaining stores collisions in a secondary structure; probing finds another slot and suffers clustering. Load factor predicts how often collisions occur.

Apply

Compare the two strategies on memory and on graceful degradation as the table fills.

Watch out

Ignoring resizing, which is an amortised cost that explains the constant-time claim.

3

Heaps

Know

The heap property constrains each parent against its own children only. That weaker ordering is why maintenance is logarithmic and the extreme sits at the root.

Apply

Use a heap when the extreme element is needed repeatedly but full sorting is not.

Watch out

Expecting sorted output from a heap. Only the root is guaranteed.

4

Priority Queues in Practice

Know

A priority queue built on a heap is the engine behind Dijkstra, scheduling, and top-k selection.

Apply

For top-k over a stream, keep a heap of size k rather than sorting everything.

Watch out

Sorting an entire stream to find a few extremes, which is asymptotically worse and often infeasible.

Emphasized in this unit

Connections and techniques that receive extra attention in this unit.

  • • Stating the hashing assumption every time
  • • Distinguishing the heap property from sortedness
  • • Using a size-k heap for top-k rather than sorting

Varies by course

Related topics some schools attach to this unit and others leave out. Covered on request rather than assumed.

  • Custom hash functions. Written by hand in some tracks.
  • Fibonacci heaps. An advanced extension.

Check yourself

  • • What assumption makes hash lookup constant on average?
  • • Why is a heap cheaper to maintain than a sorted structure?
  • • Why is a size-k heap better than sorting for top-k?

Modeling drill

From a stream of millions of values, return the 10 largest, and state both the time per element and the total memory used.

Hash functionCollisionChainingProbingLoad factorHeap propertyPriority queueTop-k

Need help with this topic?

Work through questions with a tutor and get help with the steps you find difficult.

Get help with this topic