Big O Notation & Time Complexity in Algorithm and Data Structure

Big O Notation & Time Complexity in Algorithm and Data Structure

Big O Notation is a Notation that tells you how Fast your Algorithm is.

All that matters to us in every system we manufacture is speed and security. And this is what we want when knowing Big O is the speed of the algorithm used in order to use the best algorithm to make what we want.


Let's go back a little to the Linear Search Algorithm and Binary Search

If We have an array containing more than 100 Elements. And we want to reach the last Element, of course, we can access it by using the Linear Search or Binary Search Algorithm, but we are not only interested in reaching but rather the best way to access it.

If We want to use the Linear Search Algorithm to get to the last item. Let's say that every transition to another Element takes 1 second. In order to reach the last Element, it will need one time to reach this means that it will take 100 seconds to reach the last Element.

But if We use the Binary Search Algorithm, it will take about 7 to 8 times to reach the last item, which means that it will need about 7 to 8 seconds of time.

This is exactly what we want the best way to access, so we will choose the Binary Search Algorithm


The most Important Types of Big O Notation:

  1. O(1) : constant time complexity. Like accessing a specific Element in an Array.

  2. O(n): linear time complexity. Like the Linear Search Algorithm.

  3. O(log n): logarithmic time complexity. Like the Binary Search Algorithm.

  4. O(n2) : squared time complexity. Like sort insertion and styles.

  5. O(n!): a Factorial Function.


That's it, folks! hope it was a good read for you. Thank you! ☺️