← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Interviewed at Google and got asked about sorting algorithm complexities. Pretty standard stuff but worth knowing cold.

Questions Asked (1)

Q1

What are the time complexities of Quick Sort and Merge Sort?

Algorithms & Data Structures
Author's notes

Knew this one but still fumbled the average vs worst case distinction for Quick Sort.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly stating the time complexities for both algorithms in best, average, and worst cases, then briefly explain the reasons behind these complexities, such as pivot selection for Quick Sort and the divide-and-conquer nature of Merge Sort. Finally, mention space complexity and stability to provide a complete comparison.

Pro tip: Emphasize that while Quick Sort has a worst-case O(n^2), its in-place partitioning and good cache performance often make it faster in practice than Merge Sort, which is stable and guarantees O(n log n) but requires O(n) extra space.

1. State Quick Sort complexities

Clearly specify best/average O(n log n) and worst O(n^2), and note that the worst case occurs with poor pivot choices (e.g., already sorted input with first/last pivot).

2. State Merge Sort complexities

State that Merge Sort is O(n log n) in all cases (best, average, worst) due to its consistent divide-and-conquer splitting and merging.

3. Explain the reasons

Briefly explain why: Quick Sort's partitioning can be unbalanced, while Merge Sort always divides the array in half and merges in linear time.

4. Compare space and stability

Mention that Quick Sort is in-place (O(log n) stack space) but unstable, whereas Merge Sort requires O(n) auxiliary space and is stable.

5. Discuss practical implications

Conclude with when each is preferred: Quick Sort for in-memory arrays due to cache efficiency, Merge Sort for linked lists or when stability is needed.

Key Points to Mention

  • Quick Sort average O(n log n), worst O(n^2) with poor pivot; randomized pivot gives expected O(n log n).
  • Merge Sort always O(n log n) time due to consistent halving and linear merging.
  • Quick Sort is in-place (O(log n) stack) but not stable; Merge Sort needs O(n) extra space and is stable.
  • Quick Sort often faster in practice due to better cache locality and low constant factors.
  • Merge Sort preferred for linked lists (no random access) and external sorting.
  • Worst-case for Quick Sort can be mitigated with randomized or median-of-three pivot selection.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.