Constant Time O(1) functions needs fixed amount of time to execute program or algorithm. It does not depend on number of inputs.

For example, you want to write a function that returns true or false based on the value of first element in a array. Program needs input of an integer array. If first integer in array is greater than 0, function must return true. In all other conditions, function must return false.

In the above example, function exection time does not depend on number of elements. It just check the first element and returns the result. It does not matter if function get array of 1 integer or 1 million integers. Hence we can say that running time of this function is constant. This function can be represented as O(1) time complexity.

Java is a trademark of Oracle.

Apekshit.com is just for learning and testing. To improve basic understanding we provide some examples. We are constantly reviewing it to avoid errors, but we cannot warrant full correctness of all content.