Python algorithm complexity

Asymptotic complexity describes how resource use grows with input size. It is not an exact wall-clock prediction: hardware, constants, and the operations being counted still matter.

Python
def work(n):
    linear = 0
    quadratic = 0
    for _ in range(n):
        linear += 1
    for _ in range(n):
        for _ in range(n):
            quadratic += 1
    return linear, quadratic

print(work(3))
print(work(6))
assert work(0) == (0, 0)
Read the full lesson