Constant time - No matter how large the input gets the amount of time to retrieve remains constant.

Runtime - $\mathcal{O}(1) $ - No additional time for your function to run as the input size grows.

Note This does not mean it takes one operation. It means it takes on the order of 1 That means it can be any number of operations as long as it’s fixed.

This is the best in terms of runtime, you want to achieve this at all cost…

What I don’t understand is if you have a function that’s going to process a million items of something let’s say given an array = [1,2,3,4…100,000,000] That’s going to take a million seconds to run. So how is that not additional time as the input grows? If an input is 1000 it will take 1000 seconds but but if you increase that to 2000 it will take 2000 seconds to run.

I think you are confusing linear time with constant time.

Basic Example

Prints 0..49

# constant 0(1)
def constant_run_time(N):
    for i in range(0, 10):
    return True


Complex Example

Even as the input size goes up the run time stays the same.

from stopwatch import Stopwatch

def constant_run_time(N):
    total_sum = 0
    sum = 0
    for i in range(0,50):
        total_sum += i
        return total_sum

if __name__ == "__main__":
    input_sizes = [100, 200, 400, 800, 1600, 3200, 6400]
    for input_size in input_sizes:
        timer = Stopwatch()
        print(input_size, timer.elapsed_time())


6:33 => 9:26