### big-o

#### Why this code gives big-O = O(1)

public static LinkedList third(int[] array){ LinkedList retval = null; for (int i = 0; i < 999 && i < array.length; i = i + 1) { retval = new LinkedList(array[i], retval); } return retval; } Why this code gives big-O = O(1) ?

Because the loop will be executed maximally 999 times which is a constant value therefore You can think of it as it's O(999) = O(1) = O(c), where c is a constant value. If the value of i wouldn't be limited by 999, the loop would be executed array.length times and the complexity would be O(n), where n is the size of input array.

### Related Links

Time complexity of nested for loop?

Is O(log(n*log n) can be considered as O(log n)

Time complexity of recursive algorithms with branches of different complexity

What is the difference between O(1) and Θ(1)?

Time complexity (in big-O notation) of the following code?

LSM Tree lookup time

The time complexity of O(nⁿ) and O(n!)

O notation using pseudocode

Why is multiplication n^2 time?

What is growth function and order where inner loop variable is multiplied by 2

Big O time complexity for nested j = i + 1 loop

How to calculate the running time of this algorithm?

Big-O Notation and coding

Either f(n) = O(g(n)) or g(n) = O(f(n))

Is an algorithm with asymptotic runtime complexity of θ(n) always faster runtime than a similar algorithm with runtime complexity of θ(n^2 )?

Best case of quick sort variation