Questions
41 of 59
1What is a Graph? Define Vertex, Edge, Degree.
2What is the difference between Directed and Undirected Graphs?
3What is a Weighted Graph?
4What is a Cyclic vs Acyclic Graph?
5What is the difference between a Tree and a Graph?
6Explain Adjacency Matrix. What are its pros and cons?
7Explain Adjacency List. What are its pros and cons?
8Which representation is better for Sparse vs Dense graphs?
9Explain Breadth-First Search (BFS). What data structure does it use?
10Explain Depth-First Search (DFS). What data structure does it use?
11What is the time complexity of BFS and DFS?
12What is Topological Sorting? Which algorithm is used?
13How do you detect a cycle in a Directed Graph?
14How do you detect a cycle in an Undirected Graph?
15Explain Dijkstra's Algorithm. When does it fail?
16Explain Bellman-Ford Algorithm. Why is it slower than Dijkstra?
17What is the difference between Dijkstra and A* (A-star)?
18What is a Minimum Spanning Tree (MST)?
19Explain Kruskal's Algorithm. Which data structure is crucial for it?
20Explain Prim's Algorithm.
21What is the difference between Kruskal's and Prim's? When is one preferred?
22What is Union-Find (Disjoint Set Union)? Explain Path Compression and Union by Rank.
23What is a Bipartite Graph? How do you check for it?
24How do you find the shortest path in an unweighted graph?
25Explain Strongly Connected Components (Kosaraju/Tarjan).
26What is a Directed Acyclic Graph (DAG)? Why are they important in build systems?
27How do you solve a Maze using Graph algorithms?
28Explain Floyd-Warshall Algorithm (All Pairs Shortest Path).
29How do you detect a Deadlock using a Graph?
30What is the difference between Linear Search and Binary Search?
31What is the precondition for Binary Search?
32Write down the time complexities of Bubble, Selection, Insertion Sort.
33Why is Insertion Sort preferred for small or nearly sorted arrays?
34Explain Merge Sort. What is its time and space complexity?
35Explain Quick Sort. What is its worst-case complexity? How do you avoid it?
36Compare Merge Sort vs Quick Sort. When do you choose which?
37What is Heap Sort? How does it work?
38Is Heap Sort stable? Is Merge Sort stable?
39What is Counting Sort? What are its limitations?
40What is Radix Sort? How does it handle strings?
41What is the fastest possible time complexity for a comparison-based sort? Why?
42What is the difference between Internal and External Sorting?
43How do you find the k-th largest element in an array?
44How do you find the median of a stream of numbers?
45What is a Bucket Sort? When is it effective?
46Explain the concept of Stability in sorting. Why does it matter for multi-key sorting?
47What is a Persistent Data Structure?
48What is a Treap? How does it combine BST and Heap properties?
49What is a Bloom Filter? How do you calculate the False Positive rate?
50What is an LRU Cache? How do you implement it using a Hash Map and Doubly Linked List?
51What is an LFU Cache? How is it different from LRU?
52What is a Suffix Tree/Array? What string problems does it solve?
53What is a Van Emde Boas tree?
54How do you design a Data Structure that supports insert, delete, search, and getRandom in O(1)?
55What is the Median of Medians algorithm? Why is it better than random pivot selection?
56Explain the concept of Cache Oblivious algorithms.
57What is the difference between a Binary Heap and a Fibonacci Heap? Why is Fibonacci Heap theoretically faster for Dijkstra's?
58How are Data Structures used in Database Indexing? (B+ Trees, Hash Indexes)
59How does the Garbage Collector interact with data structures? (Weak references, Gen0/Gen1/Gen2)
41 / 59

What is the fastest possible time complexity for a comparison-based sort? Why?

Difficulty: 5/10
comparison sort lower bound, algorithmic complexity, sorting algorithms

Comparison Sorting Lower Bound

The asymptotically optimal worst-case time for comparison-based sorting is O(n log n), and more precisely there is an Omega(n log n) lower bound. The proof uses a decision tree: sorting n distinct elements requires distinguishing among n! possible permutations, requiring at least log2(n!) comparisons, which is Omega(n log n).

javascript
  1. 1

    Comparison sorts cannot have asymptotically better worst-case complexity than Omega(n log n).

  2. 2

    Merge Sort and Heap Sort achieve O(n log n) worst-case time.

  3. 3

    Quick Sort achieves O(n log n) expected time with suitable randomization.

  4. 4

    Non-comparison algorithms can beat this bound by exploiting key structure.

Scenario Questions

0-2 years experience

  1. 1We need to sort a list of 10,000 user IDs in a new microservice. Which comparison‑based algorithm would you choose and why can't you do better than O(n log n) here?
  2. 2If you tried to write a custom sort that only swaps each pair of elements once, what time complexity would you end up with and why?

2-5 years experience

  1. 1Your team replaced quicksort with an in‑house sort and saw it slow down on large logs. How would you debug whether the new algorithm is violating the O(n log n) lower bound?
  2. 2When merging two already‑sorted streams in real‑time, how do you ensure the overall operation stays within O(n log n), and what trade‑offs might you consider?
  3. 3If many keys in your dataset are identical, does the comparison‑based lower bound still apply, and can you exploit that to improve average performance?

5-8 years experience

  1. 1Design a distributed sorting service that processes billions of records daily. Explain how the Θ(n log n) lower bound shapes your choice of algorithm and data partitioning.
  2. 2Your input is partially ordered (nearly sorted). How would you adapt a comparison sort to approach O(n) while still respecting the theoretical bound?
  3. 3Suppose you can augment each comparison with a cheap hash of the elements. How might that change the lower bound and your system design?

8+ years experience

  1. 1The legacy codebase uses an O(n²) custom sort. At an architectural level, how would you justify replacing it, considering the Θ(n log n) lower bound and operational cost savings?
  2. 2We need a unified sorting contract across services that supports both comparison‑based and non‑comparison sorts. How would you design the abstraction to allow future algorithms that could break the O(n log n) barrier under specific data assumptions?
  3. 3A new hardware accelerator claims to sort in O(n) time. What criteria would you use to validate that claim, and how does the comparison‑based lower bound factor into your assessment?

Follow-up Questions

  • What assumptions does the Θ(n log n) lower bound rely on?
  • Can you give an example of a sorting method that runs in linear time and why it isn’t comparison‑based?
  • How would duplicate keys affect the lower‑bound argument?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.