Handling 10 inputs is easy. Handling 10 lakh inputs is where real skill shows. That's what time complexity measures.
⚡ What is Time Complexity?
It measures how the number of operations grows as input size grows — not seconds, not milliseconds.
📊 The 4 Big-O You Must Know
O(1) — Constant Time
function getFirst(arr) { return arr[0]; } // Always 1 step
O(n) — Linear Time
function findMax(arr) {
let max = arr[0];
for (let i = 1; i < arr.length; i++) {
if (arr[i] > max) max = arr[i];
}
return max;
}
O(log n) — Logarithmic Time
Each step halves the problem. 1,000,000 elements → only ~20 steps. Example: Binary search.
O(n²) — Quadratic Time
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) { /* n×n ops */ }
}
📉 Growth Comparison Table
| n | O(1) | O(log n) | O(n) | O(n²) |
|---|---|---|---|---|
| 10 | 1 | 3 | 10 | 100 |
| 1,000 | 1 | 10 | 1,000 | 1,000,000 |
| 10,000 | 1 | 13 | 10,000 | 100,000,000 |
At 10,000 elements — O(n²) runs 100 million ops vs O(n)'s 10,000.
🎯 Interview Tip
Always analyse time complexity before and after optimising. Interviewers ask: "What's the Big-O?"
Part 4 of the Bitveen DSA Series. Originally published at bitveen.com
























