๐ŸŽฏ HOOK

The Magic Box

Imagine a magic box that gives you any item instantly if you know its number. Whether the box has 10 items or 10 million items, grabbing item #5 takes the exact same time.

๐Ÿงช EXPLORE

Instant Access Simulator

Try accessing an item from a small list vs a large list. Notice the speed!

Steps Taken
1
Time
Instant
๐Ÿ’ก EXPLAIN

What is O(1)?

Constant time means the operation takes the same amount of time regardless of the input size.

  • โœ“ Accessing an array index
  • โœ“ Hash map lookup (average)
  • โœ“ Basic math operations
  • โœ“ Pushing to a stack
# O(1) Python Example
def get_first_item(items):
    return items[0]
โœ๏ธ PRACTICE

Test Your Understanding

1. Which is O(1)?

๐ŸŽ‰

Great Start!