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 NN.

What is the time complexity?

Whether it's 5N5N, 10N10N, or 1000N1000N, 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)O(N).


This workbook was created by Jad and Rayan Slim. Feel free to explore some of their courses:
The Complete Java Development Bootcamp
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.