Big O
)}

Problem

This loop keeps running until the array's length reaches 6. Calculate the time complexity.

def loop_until_six(arr): while len(arr) > 6: arr = arr[:len(arr)//3] return arr[0]

Solution

The difference between this algorithm and Problem 12 is that the loop stops more pre-maturely. But if the input is in the thousands, whether the loop stops at 6 or 1 is insignificant. The time complexity is still logarithmic.


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.