Problem
This function returns True
if it finds an element, and False
otherwise.
def find_item(arr, element):
for i in range(len(array)):
if arr[i] == item:
return True
return False
Solution
We're only interested in the upper bound. We can expect the following runtime if the loop never finds the element.
Input Size | Steps |
---|---|
1 | 1 |
2 | 2 |
3 | 3 |
4 | 4 |
5 | 5 |
How does the runtime increase w.r.t. input size?
The number of steps is determined by the size of the array: .
What is the time complexity?
: the runtime increases linearly with the input size.
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.