Search⌘ K
AI Features

Solution: Big O of Nested Loop with Addition

Explore how to determine the Big O time complexity of nested loops involving addition in Python. Understand the execution patterns of inner and outer loops and their combined effect on runtime efficiency. This lesson helps you analyze and calculate the running time complexity to improve algorithm evaluation skills.

We'll cover the following...

Solution #

Python 3.5
n = 10 # n can be anything, this is just an example
sum = 0
pie = 3.14
for var in range(1, n, 3):
print(pie)
for j in range(1, n, 2):
sum += 1
print(sum)

The line for var in range(1,n,3): gets executed n3\frac{n}{3} ...