Linear

Runtime $\mathcal{O}(n)$

As n increases the runtime will increase just as much.

N Runtime
2 2
4 4
6 6
8 8

Description: for loop

max_element = a[0]
for i in range(0, N):
	max_element = max(a[i], max_element)

Code Breakers Example

from stopwatch import Stopwatch


def linear_run_time(N):
    total_operations = 0
    i = 1
    while i < N:
        total_operations += 1
        i += 1
    return total_operations


if __name__ == '__main__':
    input_sizes = [10000, 20000, 40000, 80000, 160000, 320000, 640000, 1280000]
    for input_size in input_sizes:
        timer = Stopwatch()
        # Additive difference not noticeable so let's record the total
        # operations
        total_operations = linear_run_time(input_size)
        print(input_size, total_operations, timer.elapsed_time())

Reference

13:15 => 15:10