liveBook · Manning

Constant time

As explained in Advanced Algorithms and Data Structures

Constant time is a running-time bound independent of the input size, up to a fixed bound.

Constant time describes a running-time bound that does not grow with the input size, provided relevant parameters remain fixed. In asymptotic notation, this is O(1). section 2.7.2 section 4.9.3

Treat an operation as constant time only after stating which quantities are independent of the growing input:

  • A heap update costing O(log k) is O(1) when k is a fixed bound that does not depend on n. section 2.7.2
  • Bloom-filter insertion takes O(k·T(|X|)); it becomes constant time for fixed k and keys whose lengths are bounded by a constant. section 4.9.3
  • Variable-length strings do not automatically permit constant time: hashing remains dependent on string length unless a maximum length is fixed. section 4.9.3 section 4.9.4
  • Constant time can be amortized, meaning occasional more expensive work is averaged across operations rather than bounded individually. section 7.4.3

Bounded Bloom-filter operations

An insertion computes k hash values and flips k bits. With fixed k and a fixed maximum key length, the work stays constant regardless of how many elements the filter already stores. Lookup has the same bounded behavior. section 4.9.3 section 4.9.4

Cache operations

An LRU cache can provide constant or amortized-constant storing, lookup, and eviction operations. An LFU cache implemented with a simple ordered list loses constant-time insertion and may require linear-time updates. section 7.4.3 section 7.5.2

Table 7.2 Comparative analysis of performance vs implementation for cache with n elements (view table figure)

 

Array (unsorted)

Linked list

Hash table

Balanced tree

LRU cache

Storing an entry

O(1)

O(n)

O(1) a

O(log n)

O(1)a

Finding entry by name

O(n)

O(n)

O(1)a

O(log n)

O(1)a

Eviction

O(n)

O(1)

O(n)

O(log n)

O(1)a

Compare constant-time storing, lookup, and eviction across arrays, linked lists, hash tables, balanced trees, and LRU caches. section 7.4.3

How Advanced Algorithms and Data Structures covers it

How deep it goes
Defines O(1) through heap, hashing, key-length, and amortization cases, but stops short of formal proofs.
Examples
Uses bounded heap updates, Bloom-filter insertion and lookup, LRU-cache operations, and inefficient LFU-list updates as examples.
What you can do after
Evaluate whether an operation is O(1) by identifying growing inputs, fixed bounds, key-length limits, and amortization.
How it connects
Connects constant time to big-O notation, amortized analysis, hash tables, Bloom filters, priority queues, LRU caches, and LFU caches.

Also explained in

Compare how 7 books explain constant time →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Advanced Algorithms and Data Structures. The section links point to the parts of the book it draws on.