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 Size | Loops |
---|---|
1 | 5 |
2 | 10 |
3 | 15 |
4 | 20 |
5 | 25 |
How does the runtime increase w.r.t. input size?
The number of loops is 5 times the input size .
What is the time complexity?
Whether it's , , or , 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 .
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.