December 27, 2021

Complexity Analysis

Often times there are many solutions to a problem and choosing the best or optimal solution depends on how it performs and the resources it consumes.The performance and efficiency of a program or an algorithm is measured by two complexity measures, time complexity and space complexity.

For this analysis lets consider an example of adding all the values in a list using a loop.

def sum_of_list(int_list):
    total = 0
    for val in int_list:
        total = total + val
    return total

Time Complexity

Space Complexity

Big-O Complexity Chart

Screen-Shot-2021-12-27-at-8.02.55-AM

In general, time complexity is more important than the space complexity as time taken to compute cannot be shortened easily and compute cost more with storage and memory getting cheap now a days.