Big O notation: — Order of (notation)

Why does this method exist?

Because it gives us a simple function of time versus iteration.

  1. O(1): constant time, in code it is a simple line of code
  2. O(n): linear time, one loop of n(length) in the code
  3. O(n²): quadratic time, nested loop in the code
  4. O(n^k): polynomial time, algorithm examples, quicksort, insertion sort.
  5. O(log n): logarithmic time, algorithm examples, binary search.
  6. O(n log n): linearithmic time, examples, merge sort, heapsort.

How does it works?

O(n), is like f(x) when O stand for order of, and n is the length of the input for a given function. When calculating big O we need to look at the operation to measure and determent those things:

  1. Firstly go throw the code line by line and establish whether it’s O(1), O(n) etc. by the worst case scenario.
  2. Add up all the big O of each line to the final big O. should look something like this O(10 + 3n +n²), depends on your algorithm
  3. Lastly, take only the biggest exponent of n. In our example — O(n²).

--

--

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
Reem Mikulsky

Reem Mikulsky

23 Followers

I’m a 17 years old boy that is interested in the future and technology