Data Structures & AlgorithmsModerateTCS NQT · sorting
Problem: In counting sort, what limits its use on a large input?
- A. The input must be sorted already
- B. The key range must be small compared with n
- C. It requires floating-point keys
- D. It needs a heap
Correct answer: B. The key range must be small compared with n
Counting sort runs in O(n + k) time, so a large key range k makes it slow and memory-hungry.
More Coding Interview Problems questions
- Problem: What does the expression 'x & (x - 1)' clear in the binary representation of x?
- Problem: Which algorithm solves the 'minimum cost to connect all points' in the Euclidean plane with n points in O(n^2) time (dense graph)?
- Problem: What is the time complexity of building a trie for n strings of total length L?
- Problem: What is a 'bridge' in an undirected graph?
- Problem: Which algorithm finds the strongly connected components of a directed graph using a single DFS with a stack?
- Problem: What is the maximum number of edges in a bipartite graph on n vertices with sides of size n/2?