DSA, Database System & Operating System — Sorting, Searching, and Graphs, NEC licence examination syllabus (Nepal Engineering Council).
Compute where a key belongs instead of searching for it — and then deal with the fact that two keys will eventually compute the same answer.
A hash function turns a key into an array index. Instead of searching a structure, you calculate the position directly and go there — one step, whatever the table's size. That is the O(1) average lookup that makes hash tables the default choice for dictionaries and sets.
HowEach slot holds a linked list. Colliding keys are appended to it.
CostLookup is one hash plus a short list walk.
BehaviourDegrades gracefully — the table can hold more entries than it has slots.
HowOn collision, probe for another empty slot — linear probing tries the next slot, quadratic probing steps further each time, double hashing uses a second hash to decide the step.
CostNo extra structures; everything lives in the array.
BehaviourDegrades sharply as the table fills, and cannot exceed its own size.
Uniform — spreads keys evenly, so no slot attracts more than its share. Fast — it runs on every operation, so an expensive hash cancels the benefit. Deterministic — the same key must always hash to the same slot, or nothing can ever be found again.
A prime table size helps with the simple modulo hash, because a composite size shares factors with patterned keys and collapses them onto a few slots — keys that are all multiples of 4 in a table of size 8 use only half the slots.
O(1) as a guarantee. It is the average. Worst case is O(n), when every key collides.
Chaining and probing. Chaining stores collisions outside the array; probing finds another slot inside it.
Hashing and encryption. A hash is one-way and not reversible by design; it is not a way to hide data.
Compute the position instead of searching — O(1) average, O(n) worst.
Collisions are unavoidable, so the resolution strategy is the design decision.
Chaining tolerates α > 1; open addressing degrades sharply as α approaches 1.
Linear probing causes primary clustering.
Resizing requires rehashing every key, because the hash depends on the table size.
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.
Loading…