What is the main idea behind the Divide and Conquer strategy?
Divide and Conquer breaks a problem into smaller parts, solves each part separately, and then combines the results to solve the original problem.
Click to reveal answer
beginner
What does a recurrence relation describe in algorithms?
A recurrence relation expresses the running time of a recursive algorithm in terms of the running time of smaller inputs.
Click to reveal answer
intermediate
Explain the recurrence relation for Merge Sort.
Merge Sort splits the array into two halves, sorts each half, and merges them. Its recurrence is T(n) = 2T(n/2) + O(n), where O(n) is the merging time.
Click to reveal answer
intermediate
What is the Master Theorem used for?
The Master Theorem helps solve recurrence relations of divide and conquer algorithms to find their time complexity quickly.
Click to reveal answer
beginner
Give an example of a problem solved by Divide and Conquer.
Sorting an array using Merge Sort or Quick Sort is a classic example of Divide and Conquer.
Click to reveal answer
Which step is NOT part of the Divide and Conquer approach?
ADivide the problem into smaller subproblems
BSolve the subproblems independently
CCombine the solutions of subproblems
DIgnore the smaller subproblems and solve the big problem directly
✗ Incorrect
Divide and Conquer always breaks the problem into smaller parts instead of ignoring them.
What does the recurrence T(n) = 2T(n/2) + n represent?
ABinary search time
BLinear search time
CMerge Sort time complexity
DConstant time operation
✗ Incorrect
This recurrence describes Merge Sort, which divides the problem into two halves and merges in linear time.
Which theorem helps solve recurrences like T(n) = aT(n/b) + f(n)?
APythagorean Theorem
BMaster Theorem
CBinomial Theorem
DFundamental Theorem of Calculus
✗ Incorrect
The Master Theorem is designed to solve divide and conquer recurrence relations.
In Divide and Conquer, what is the typical time complexity of combining solutions?
ALinear time
BConstant time
CExponential time
DLogarithmic time
✗ Incorrect
Combining solutions often takes linear time, like merging two sorted arrays.
Which of these is NOT a Divide and Conquer algorithm?
ABubble Sort
BMerge Sort
CBinary Search
DQuick Sort
✗ Incorrect
Bubble Sort is a simple sorting algorithm that does not use Divide and Conquer.
Describe the three main steps of the Divide and Conquer strategy with an example.
Think about how sorting an array can be done by splitting, sorting parts, and merging.
You got /4 concepts.
Explain how recurrence relations help analyze the time complexity of recursive algorithms.
Consider how the time for a problem depends on smaller problems.
You got /4 concepts.
Practice
(1/5)
1. What is the main idea behind the Divide and Conquer strategy in algorithms?
easy
A. Break the problem into smaller subproblems, solve them independently, then combine results
B. Solve the problem by trying all possible solutions one by one
C. Use a single loop to process all elements sequentially
D. Store all intermediate results to avoid repeated calculations
Solution
Step 1: Understand the divide and conquer approach
It splits a big problem into smaller parts that are easier to solve separately.
Step 2: Combine the solutions of subproblems
After solving smaller parts, their results are combined to get the final answer.
Final Answer:
Break the problem into smaller subproblems, solve them independently, then combine results -> Option A
Quick Check:
Divide and conquer = split, solve, combine [OK]
Hint: Divide big problem into smaller parts, solve, then combine [OK]
Common Mistakes:
Confusing divide and conquer with brute force
Thinking it processes elements sequentially only
Mixing it up with dynamic programming
2. Which of the following is the correct recurrence relation for the Merge Sort algorithm?
easy
A. T(n) = T(n/2) + O(1)
B. T(n) = 2T(n/2) + O(n)
C. T(n) = T(n-1) + O(1)
D. T(n) = 3T(n/3) + O(n^2)
Solution
Step 1: Recall Merge Sort divides array into two halves
It splits the array into two parts, sorts each recursively.
Step 2: Merge step takes linear time O(n)
After sorting halves, merging takes O(n) time.
Final Answer:
T(n) = 2T(n/2) + O(n) -> Option B
Quick Check:
Merge Sort recurrence = 2T(n/2) + n [OK]
Hint: Merge sort splits in two, merges in linear time [OK]
Common Mistakes:
Using T(n-1) instead of T(n/2)
Confusing merge cost as constant time
Choosing wrong number of recursive calls
3. What is the output of the following C# code that uses a divide and conquer approach to sum an array?
int SumArray(int[] arr, int start, int end) {
if (start == end) return arr[start];
int mid = (start + end) / 2;
return SumArray(arr, start, mid) + SumArray(arr, mid + 1, end);
}
int[] nums = {2, 4, 6, 8};
Console.WriteLine(SumArray(nums, 0, nums.Length - 1));
medium
A. 20
B. 10
C. 0
D. Throws runtime error
Solution
Step 1: Understand the recursive sum function
The function splits the array into halves until one element remains, then sums back up.
Step 2: Calculate sum of array elements
Sum = 2 + 4 + 6 + 8 = 20.
Final Answer:
20 -> Option A
Quick Check:
Sum of {2,4,6,8} = 20 [OK]
Hint: Divide array, sum halves recursively, add results [OK]