Search⌘ K
AI Features

Solution: Nested Loop with Multiplication (Pro)

Explore how to evaluate the time complexity of nested loops combined with multiplication operations in Python. Learn to determine the Big O notation by analyzing each loop's execution and understand how to simplify running time calculations for algorithm efficiency.

We'll cover the following...

Solution

Python 3.5
n = 10 # can be anything
sum = 0
pie = 3.14
j = 1
for var in range(n):
while j < var:
sum += 1
j *= 2
print(sum)

The outer loop in the main function has ...