Questions
42 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)
42 / 59

What is the difference between Internal and External Sorting?

Difficulty: 5/10
sorting algorithms, memory management, I/O

Internal vs External Sorting

Internal sorting assumes the entire dataset fits in main memory, so the algorithm primarily optimizes CPU operations and RAM access. External sorting is required when the dataset is larger than available memory and therefore uses secondary storage. External Merge Sort is a standard approach because it minimizes expensive disk I/O.

javascript
  1. 1

    Internal sorting: entire dataset fits in memory.

  2. 2

    External sorting: dataset exceeds memory capacity.

  3. 3

    External algorithms optimize I/O rather than only comparisons.

  4. 4

    External Merge Sort is common for large database files.

Scenario Questions

0-2 years experience

  1. 1Suppose you need to sort a list of 10,000 integers on a device with only 1 MB of RAM. Would you choose an internal or external sorting approach, and why?
  2. 2If you implement quicksort on an array that fits entirely in memory, what could go wrong if the input size suddenly grows beyond memory limits?
  3. 3How would you modify your sorting code to handle a file that’s too large to load into RAM?

2-5 years experience

  1. 1Your team added a feature that streams log entries from disk and sorts them before displaying. Performance dropped dramatically. Walk me through how you’d diagnose whether the issue is due to using an internal sort on data that should be external.
  2. 2We have a batch job that merges several sorted CSV files stored on S3. The current implementation loads each file into memory before merging. What trade‑offs would you consider to switch to an external merge sort?
  3. 3During a code review you notice a function that reads a 2 GB dataset into a list and calls Collections.sort. The service crashes on production. Explain why this happened and how you’d fix it.

5-8 years experience

  1. 1Design a service that continuously receives unsorted events and must provide the top‑k sorted results in near real‑time, while the total event volume exceeds available RAM. How would you combine internal and external sorting techniques?
  2. 2Our analytics pipeline processes terabytes of clickstream data nightly. We need to sort by timestamp before aggregation. Discuss the architecture choices, including when to use external sort, how to partition data, and how to minimize I/O.
  3. 3Explain how you would implement a fault‑tolerant external sort in a distributed system, handling node failures and ensuring the final output is correctly ordered.

8+ years experience

  1. 1We are migrating a legacy data warehouse that uses a custom external merge sort written in C to a cloud‑native platform. What architectural considerations would you evaluate to decide whether to keep the external sort, replace it with a managed service, or redesign the data model?
  2. 2Across multiple teams, there’s a debate about standardizing on internal vs external sorting for large batch jobs. How would you create a guideline that balances performance, cost, and developer productivity, and how would you drive adoption?
  3. 3Our company plans to store petabytes of time‑series data that must be sorted for range queries. Propose a long‑term strategy that addresses storage layout, sorting methodology, and future scalability, including any trade‑offs with external sorting.

Follow-up Questions

  • What are the main I/O costs associated with external sorting?
  • How would you decide the point at which to switch from an internal to an external algorithm?
  • Which metrics would you monitor in production to detect that an internal sort is no longer viable?
Share

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