Count the steps: scan, halve, hash
The numbers are steps, not seconds, so they are the same on every computer.
Every container makes some operations cheap and others expensive. This topic explains Big-O in plain words, compares the cost of the common operations on lists, deques, sets and dictionaries, and gives a short guide for choosing on purpose.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
You have emails = [...] with 50,000 items and must test thousands of addresses against it. Show how to set it up for fast tests, using a short example list.
Which container would you use for: (a) the last 5 messages of a chat, (b) the number of times each word appears, (c) unique visitor ids? Print your answers as three lines.
Write a loop that counts how many steps a linear search takes to find 7 in [3, 9, 7, 1] and print the count.
Explain it without notes
What does O(1), O(n) and O(n²) mean, with one Python example of each?
Why is x in my_set O(1) but x in my_list O(n)?
When would you use a deque instead of a list?
How would you speed up a loop that checks if name in names against a list of 100,000 names?
How would you find the 3 largest numbers in a list of a million numbers, and what does each approach cost?
Expected output
list scan: 1000000 steps
binary search: 20 steps
dictionary lookup: 1 hash and 1 slot ( 1000 keys stored )