1. Gyanastra
  2. Data Structures
  3. Hashing
  4. Search as the Dominant Operation on Static Data Sets
Free lesson, no account needed 4 min read 2 practice questions after it

Data Structures · Hashing

Search as the Dominant Operation on Static Data Sets

Overview

A data structure mainly stores data, either as input to an algorithm or to hold its output. Many real data sets are static, so search becomes the dominant operation; hashing is a design that makes this search as fast as possible, achieving O(1)O(1) average search time.

Key concepts

  • Three standard operations: every data structure supports insert (add an element), search (find a particular element) and delete (remove an element).
  • Static data set: a data set that is created once and rarely changes — elements are inserted and then left as they are, without modification.
  • Dominant operation: on static data sets, search is the operation performed most often, so data structures are designed with search in mind.
  • Hashing: a data structure design whose purpose is to make searching faster, giving O(1)O(1) average search time.

How it works

  1. Conventional structures give limited search performance: unsorted array O(n)O(n), sorted array O(log⁡n)O(\log n) (binary search), linked list O(n)O(n), binary tree O(n)O(n) (traversal), normal BST O(n)O(n) worst case, height-balanced BST O(log⁡n)O(\log n), priority queue O(1)O(1) for min/max but O(n)O(n) for an arbitrary element.
  2. The best possible search time on most of these structures is O(log⁡n)O(\log n).
  3. Because search is used so frequently, the goal arose to minimise search time as much as possible.
  4. The solution is hashing: with hashing, the average time to search an element is O(1)O(1), i.e. constant time.

Formulas

  • Unsorted array search: O(n)O(n)
  • Sorted array search (binary search): O(log⁡n)O(\log n)
  • Linked list search: O(n)O(n)
  • Binary tree search (traversal): O(n)O(n)
  • Normal BST search, worst case: O(n)O(n) (height can be O(n)O(n))
  • Height-balanced BST search: O(log⁡n)O(\log n) (height is O(log⁡n)O(\log n))
  • Priority queue, search min or max: O(1)O(1)
  • Priority queue, search an arbitrary element: O(n)O(n)
  • Hashing search, on average: O(1)O(1)

Comparison

Data structureTime to search an elementReason
Unsorted arrayO(n)O(n)May compare with all elements
Sorted arrayO(log⁡n)O(\log n)Binary search
Linked listO(n)O(n)May scan the entire list
Binary treeO(n)O(n)Traversal needed
Binary search tree (normal)O(n)O(n) worst caseTree can become a linked list; height can be O(n)O(n)
Height-balanced BST (AVL, red-black, 2-3 tree)O(log⁡n)O(\log n)Height is O(log⁡n)O(\log n)
Priority queue (min heap / max heap) — search min or maxO(1)O(1)Min/max directly available
Priority queue (min heap / max heap) — search a particular elementO(n)O(n)Must examine elements
HashingO(1)O(1) on averageHashing technique

Revision summary

  • The three standard operations are insert, search and delete.
  • A static data set is created once and rarely changes; search is its dominant operation.
  • The best search time with conventional structures is O(log⁡n)O(\log n) (sorted array, balanced BST).
  • A normal BST degrades to a linked list in the worst case, giving O(n)O(n) search; balancing (AVL, red-black) brings it to O(log⁡n)O(\log n).
  • In a heap, min/max search is O(1)O(1) but searching an arbitrary element is O(n)O(n).
  • Hashing gives O(1)O(1) search on average — the average qualifier must not be dropped.

Previous-year exam insights

  • Hashing gives O(1)O(1) average search time but O(n)O(n) worst case, because all keys can collide into the same slot; the worst-case bound must not be confused with the average.
  • The load factor α = n/m (number of stored keys divided by number of slots) determines performance;
    with chaining, unsuccessful search takes Θ(1+α) and successful search Θ(1+α) on average, and open addressing requires α < 1.
  • A good hash function should be easy to compute and distribute keys uniformly (e.g. division method h(k)=k mod m with m prime, or multiplication method);
    a poor hash function causes clustering and degrades search toward O(n)O(n).
  • Collision resolution methods: separate chaining (each slot holds a linked list) and open addressing (linear probing, quadratic probing, double hashing); linear probing suffers primary clustering, and deletion in open addressing needs tombstones/lazy deletion.
  • Hashing does not support efficient ordered operations: finding the minimum/maximum, predecessor/successor, or printing keys in sorted order takes O(n)O(n) (or O(nlog⁡n)O(n \log n) by sorting), so a balanced BST is preferred when order matters.
  • In a min-heap or max-heap, insert and delete-min/delete-max take O(log⁡n)O(\log n) and building a heap takes O(n)O(n); only the root is directly accessible in O(1)O(1).
Pages 1–2 of 2