liveBook · Manning

Constant time

As explained in Python Workout: 50 ten-minute exercises

An asymptotic time complexity that remains bounded independently of the number of elements processed.

Constant time, written O(1), describes work that stays bounded as the number of processed elements grows. Looking up an employee by a directly calculated office number takes the same time for 2, 25, or 250 employees. section 4.1

Hash-based lookup

A dictionary uses a hash function to map a key to a storage location. Retrieving d['a'] hashes 'a' and checks the indicated slot, making the lookup effectively constant time. Collisions—such as two names beginning with S—may require checking several entries. section 4.1

How Python Workout: 50 ten-minute exercises covers it

How deep it goes
Explains bounded growth through an office analogy and dictionary mechanics, while acknowledging collisions without detailing their implementation.
Examples
Uses alphabet-indexed office searches and Python dictionary retrieval to illustrate constant-time access.
What you can do after
Evaluate whether direct lookup remains bounded as the collection grows, including the effect of collisions.
How it connects
Connects constant time to hash functions, dictionaries, mappings, key-value pairs, and collisions.

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 Python Workout: 50 ten-minute exercises. The section links point to the parts of the book it draws on.