Data structure operations
What Big-O means
Big-O describes how the running time (or memory) of an algorithm grows as the input size n grows, ignoring constants and smaller terms. O(n) means doubling the input roughly doubles the work; O(n²) means it quadruples; O(log n) means doubling the input adds just one more step.
Quick rules for interviews
- Drop constants: O(2n) → O(n). Drop smaller terms: O(n² + n) → O(n²).
- Sequential steps add (O(a + b)); nested loops multiply (O(a × b)).
- Halving the problem each step gives O(log n) — binary search, balanced trees.
- Recursion: count calls × work per call. Two calls each on n−1 → O(2ⁿ).
- Hash maps are O(1) average, O(n) worst case (collisions).
- Always mention space too — recursion depth and extra arrays count.
Growth at n = 1,000
log n ≈ 10 · n = 1,000 · n log n ≈ 10,000 · n² = 1,000,000 · 2ⁿ has 302 digits. That is why an O(n²) solution often times out on n = 10⁵ while O(n log n) finishes instantly.
More Interview & Career
🗄️SQL PracticeOnline SQL playground with 27 interview challenges
🎤Interview Question Practice125+ HR, DSA, SQL, system design & AI/ML questions
⭐STAR Answer BuilderBuild structured answers to behavioural questions
📝Resume Bullet BuilderWrite strong XYZ resume bullets with action verbs & metrics
💰Salary Calculator (CTC → In-Hand)India CTC to in-hand salary, new vs old tax regime
📊Sorting Algorithm VisualizerWatch bubble, merge, quick, heap sort step by step