Skip to main content

Command Palette

Search for a command to run...

Big O Notation & Time Complexity in Algorithm and Data Structure

Published
2 min read
Big O Notation & Time Complexity in Algorithm and Data Structure
K

Blockchain Develoepr Inspirational with layers and building on rollups (optimistic & zk). Building Web3Arabs

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! ☺️

A

Thanks for sharing such valuable info🥰

1

More from this blog

Khairallah AL-Awady | Technical Blog

5 posts

Khairallah is a software engineer specializing in full-stack web development. Interested in contributing to open source and building Web3 applications.