Big O
)}

Problem

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

def loop_until_one(arr): while len(arr) > 1: arr = arr[:len(arr)//3] ## divides array by 3

Solution

Input SizeSteps
31
92
273

How does the running time increase w.r.t the input?

The running time's rate of increase is log3Nlog_3N. The number of steps reflects how many times the input size can be divided by 3.

What is the time complexity?

O(logN)O(logN)


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.