Big O notation

Photo by Luke Chesser on Unsplash

Big O notation is how hard an algorithm has to work to solve a problem or, in technical terms, the worst-case run time for an algorithm.

O(1) — Constant run-time algorithm.

This is an algorithm that returns an element in a known position regardless of the data size or array. For instance, designing an algorithm to test if the first element of an array is equal to the second.

O(n) — Linear run-time algorithm

For this algorithm, the number of iterations grows as the number of array elements. This is expressed as (n-1) where n is the number of array elements. If an array has 10 elements, the algorithm will require 9 comparisons.

O(n2) — Quadratic run-time algorithm

This squares the number of iterations or even quadruples. Suppose you have an algorithm that tests if an array element is duplicated elsewhere in the array. In testing, The first element must be compared with every other element in the array. The second element must be compared with every other element except the first. The third element must be compared with every other element in the array except the first two.

O(log n) — Logarithmic run-time algorithm

The algorithm splits the data into smaller portions to solve in iteration. This algorithm is perfect for very large data.

This has been a short article but I hope it gives some bit of idea,

Thank you.

--

--

--

I am a self-taught software developer in React JS. I enjoy working in teams.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Globalization functionality in Stimulsoft Reports

Solve Leetcode Problems and Get Offers From Your Dream Companies

How to create bullet chart in Apache Superset

Static Libraries in C programming

What’s new with AWS: AWS Glue

v1.6.15 Patch notes

CS373 Spring 2020: Final Entry

Software Development Process Models

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Michael Kasingye

Michael Kasingye

I am a self-taught software developer in React JS. I enjoy working in teams.

More from Medium

How to solve the “Fibonacci Number modulo M” Problem in Java

Fibonacci numbers

VERY Basic Differences Between Java and JavaScript-Arrays

Maximum Sum Triplet → InterviewBit Arrays Problem

SOLID Principles