📅 Date: July 1, 2026
🧠 Mood: The Hacker 💻
🔥 Topic: DSA Day 79: The Logarithmic Leap $O(\log N)$
✂️ Halving the Search Space
We wrap up Part 1 of Time and Space Complexity with the holy grail of algorithmic optimization: Logarithmic Time Complexity.
To truly understand this, I had to review some high school mathematics. In Computer Science, when we say $\log$, we are almost always talking about Base 2 ($\log_2$). If $2^3 = 8$, then $\log_2(8) = 3$. It essentially answers the question: "How many times can I divide this number by 2 before I reach 1?"
⚡ Binary Search vs. Linear Search
This math directly translates into Binary Search.
The Power of $O(\log N)$
If you are searching for a specific number in a sorted array of 1,000,000 elements using a standard loop ($O(N)$), it could take up to 1,000,000 checks.
If you use Binary Search ($O(\log N)$), you cut the array in half every single step.
Step 1: 500,000 left.
Step 2: 250,000 left.
By step 20, you have narrowed it down to 1 element.
Going from 1 million operations to just 20 operations is why massive tech companies obsess over logarithmic algorithms. Understanding the difference between Linear and Logarithmic scaling is the absolute baseline requirement for clearing technical interviews. Module complete.
No comments:
Post a Comment