"Big O, Big Impact: A Simple Guide to Time Complexity and base of DSA"

HIMALHIMAL
4 min read

Sending high storage game to a Friend: The 5KM, 60GB Challenge!

Final exams are done. Your buddy lives just 5 km away, and you want to gift him a copy of GTA V — all 60 GB of it.

Both of you have “awesome” 4G connections... but there’s a catch:
👉 1 GB/day data limit!

So... how on earth do you send that massive game over?
💡 Will you:

  • Burn it to a USB stick and bike it over?

  • Wait two months using your data plan?

  • Find a clever offline or local network hack?

Let’s break it down!

The best way to send him the game is by copying the game to a Hard disk and send it, Will yo do the same thing for Sending a game like minesweeper which is in kb of size ? No because you can send it via internet. As the file size grows, time taken by online Sending increases linearly f(n’). As the file size grows, time taken by physical sending remains Constant. For example if your friend is 10 min away it will always take 10 min whether it is 5gb, 50gb or 100gb but may be more efficient in case of low end game like minesweeper which takes mins. Same goes in case of designing algorithm. If you don’t know what is algorithm, It is a process of implementing you logic in program which can differ from person to person since one problem can have multiple solution.

Why it matters?

Similar to above example, In real world, Computer’s memory usage and processor usage is precious. For this efficient data structure and algorithm has to be used. For example, You want to check whether number is prime or not for example 8 in this case. The first algo that comes in mind is dividing number from 2 to 8, if any number divides or gives remainder ‘0’ from 2 to 8 then its not prime excluding 8. You can easily implement this logic in your code but if i said you should generate best possible logic which takes minimum operation then it can hinder you sometime. This is where algorithm comes to play and every problem has it best solutions and worst too. In this case of prime number, you can divide 8 from 2 to 4, since there is no any number 8 can be divided greater than 4 except itself. You may say why it matters it only saves 4 operation but in case of ‘8164427721659987003’ it saves ‘4082213860829993501’ many operation using this logic. Similarly, there is best possible way to do it in this case nut it not the best but isn’t the worst.

Time complexity

This type of algorithm can be measured in mathematical equation. The best Algorithm is measured in worst case scenario which called time complexity and space complexity. Most people think ‘Time Complexity” is a amount of time it takes to give output given problem but it is not. The same Algorithm might perform fast depending upon system and specification. In Reality, It doesn’t measure actual seconds, but instead shows how the number of operations increases when the input gets bigger.

It is measured in mathematical equation like linear, quadratic, exponential and so on using Big O notation “O”. The diagram below contains detail explanation.

Time Complexity And Why Is It Essential? | Jaro Education

What is Big O?

👉Big O notation is a way to describe how the runtime or space used by an algorithm grows as the size of the input (usually called n) increases.

It tells us:

  • The upper bound (worst-case scenario) of an algorithm’s performance.

  • How the algorithm scales when the input gets really big.


Example of Big O Types

Big OMeaningExample
O(1)Constant time → time doesn’t change as input growsAccessing an array element by index
O(log n)Logarithmic time → input size shrinks each stepBinary search
O(n)Linear time → time grows directly with inputLooping through a list
O(n log n)Linearithmic → faster than O(n²), used in efficient sortsMerge sort
O(n²)Quadratic → time grows fast (nested loops)Checking all pairs
O(2ⁿ)Exponential → time doubles with each extra inputSolving the traveling salesman brute-force
O(n!)Factorial → extremely slow for large nGenerating all permutations

Key Idea

Big O hides constants and focuses on the part that grows fastest as n increases.
Example: 5n + 100 → Big O = O(n) (because n is the dominant term)

1
Subscribe to my newsletter

Read articles from HIMAL directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

HIMAL
HIMAL