DSA Day 76: Time Complexity & Big O Notation

📅 Date: June 28, 2026

🧠 Mood: The Analyst 📈

🔥 Topic: DSA Day 76: Time Complexity & Big O Notation

⏱️ The Ultimate Metric of Scaling

If you go to the gym and lift weights without tracking your progressive overload, you are just wasting energy. The exact same rule applies to software engineering. Writing a loop that processes 10 items is easy. But what happens when that same loop has to process 10 million items? Today, the DSA curriculum hit the most critical topic for interviews: Time Complexity and Big O Notation.

Time complexity is not about measuring the execution time in seconds. A modern processor will execute bad code fast if the input is small. Time complexity is a mathematical model that describes how the runtime of your code scales as the input size ($N$) grows towards infinity.


📏 Understanding Big O Notation

In the industry, we only care about the worst-case scenario. That is what Big O Notation represents. It is the absolute maximum limit of time your code will take to execute.

1. Constant Time: O(1)

This is the holy grail. Whether your array has 10 elements or 10 billion elements, accessing arr[5] takes the exact same amount of time. The operation does not scale with the input.

2. The Golden Rule: Drop the Constants

If you have a function that loops through an array twice, the math formula might look like $O(2N)$. In Big O Notation, we drop the constants. As $N$ approaches infinity, the multiplier '2' becomes irrelevant. The final time complexity is strictly evaluated as $O(N)$. We also drop lower-order terms. An equation of $O(N^2 + N + 5)$ is simplified immediately to just $O(N^2)$.

No comments:

Post a Comment