Big O
)}

Problem

This loop runs n * 5 times. What is the time complexity?

def increment_by(n):
result = 0
for i in range(n * 5):
result += 1
return result

Solution

Input SizeLoops
15
210
315
420
525

How does the runtime increase w.r.t. input size?

The number of loops is 5 times the input size $N$.

What is the time complexity?

Whether it's $5N$, $10N$, or $1000N$, always drop the constant. Never try to be specific. The runtime is proportionately linear to the input size, and it follows that the time complexity is $O(N)$.

The Complete Spring Boot Development Bootcamp – Become a Java Web Developer

Feedback Summary
0.0
0 students
5

0%
4

0%
3

0%
2

0%
1

0%
Written Reviews
There are no written reviews yet.