DEV Community

Ratik Mahajan
Ratik Mahajan

Posted on

Algorithm with different complexity Big O Notation

There are usually 5 type of algorithm complexities that belongs to the alogorithm . Aim of the good programmer is to write the algorithm which has good performance and complexity is reduced relative to the input data. they are relative to the input that we give to the algorithm in the java programming. below are the 5 types of the big 0 notation used.

O(1) constant complexity : this is constant time complexity. it would mean that irrespective of the data, alogrithm would take same and constant time to do an operation. the efficiency of these algorithm remain constant with the input data. some of the example of this complexity is data dictionary, key value pairs.

O(n): linear complexity: this is linear time notation. this would mean that for the input size of n , n steps would be executed and as the input is increased. more time and more steps would be taken by the algorithm or the piece of code.

O(n*n) quadratic complexity: this is the worst case scenario for many searching and sorting technique, that we use. this would mean that as the input size increase the time taken by algorithm would almost double . we want to use them for the small input data, as they perform good with small input data. but as the input data is increased, performance of these algorithm decreases.

Logarithmic complexity.O(n log n) : this would mean that the with the increase in the input data, steps or the complexity and time taken would increase, but it will increase at the rate of log of n. usually base of log is 2, as we half the input size and data.

Exponential Complexity: these algorithm have runtime complexity of O(kN) . the example of these algorithm is the brute force algorithm to search the password and travelling salesman problem. the time exponentially increase and the study is still going on to make them better.

Top comments (0)