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.

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay