Quiz

Big-O Intuition

Big-O describes how the work grows as the input size n grows. It ignores small details and keeps the big picture:

Big-O Name Example n = 1,000 to 2,000
O(1) constant d[key], x in a_set same time
O(log n) logarithmic binary search one extra step
O(n) linear x in a_list, one loop 2× the time
O(n log n) linearithmic sorted(), merge sort a bit over 2×
O(n²) quadratic a loop inside a loop 4× the time

For O(n²), doubling n means (2n)² = 4n²: four times the work.

def matching_pairs(crates):
    pairs = 0
    for a in crates:
        for b in crates:
            if a != b and a.weight == b.weight:
                pairs += 1
    return pairs

With 1,000 crates this takes 2 seconds. Roughly how long will it take with 2,000 crates?