Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern
Using the master theorem, what is the solution of T(n) = 2T(n/2) + n?
- A. Θ(n log n)
- B. Θ(n)
- C. Θ(n²)
- D. Θ(log n)
Correct answer: A. Θ(n log n)
a = 2, b = 2, so n^(log_b a) = n, which equals f(n) = n: case 2 gives Θ(n log n). This is the merge sort recurrence.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- In the activity selection problem (choose the most non-overlapping intervals), which greedy rule always gives an optimal answer?
- Why does the greedy method (best value-per-weight first) solve the fractional knapsack problem but not the 0/1 knapsack problem?
- How many edges does a complete undirected simple graph on 10 vertices have?
- What is the time to search for a word of length L in a trie that holds n words?
- An undirected graph has 12 vertices and the sum of the degrees of all vertices is 40. How many edges does it have?
- The preorder traversal of a BST is 8, 5, 1, 7, 10, 12. What is its postorder traversal?