Data Structures & AlgorithmsHardCAT · GATE CS
Problem: What is the time complexity of the standard recursive merge sort, including the merge step, expressed via its recurrence T(n) = 2T(n/2) + O(n)?
- A. O(n)
- B. O(log n)
- C. O(n^2)
- D. O(n log n)
Correct answer: D. O(n log n)
By the master theorem, a recurrence of the form T(n)=2T(n/2)+O(n) (dividing into two equal halves with linear-time combining) resolves to O(n log n).
More Coding Interview Problems questions
- Problem: Which statement about the time complexity of checking if two strings are anagrams is most efficient and correct?
- Problem: For the 'minimum number of platforms needed for a railway station given arrival and departure times' problem, what is the…
- Problem: Which correctly describes why a hash set gives O(1) average-case membership testing, but a balanced BST set gives O(log n)?
- Problem: Which of these correctly explains why BFS (not DFS) is used to find the shortest path in an unweighted graph?
- Problem: What is the time complexity of detecting a cycle in an undirected graph using Union-Find, processing E edges?
- Problem: A recursive solution explores every possible way to partition a string into palindromic substrings (palindrome partitioning)…