Divide and Conquer Alogrithms Flashcards
(75 cards)
What is the Max Subarray Problem?
It asks for indices i and j in an array A such that A[j] - A[i] is maximized, and i ≤ j.
What is the practical application of the Max Subarray Problem mentioned in the lecture?
Retrospective stock trading — determining when to buy and sell for maximum profit.
What is the constraint on buying and selling in the Max Subarray Problem?
No short selling; you must buy before you sell (i ≤ j).
What is the time complexity of the brute force solution?
Theta(n^2)
How does the brute force solution work?
It uses two nested loops to evaluate A[j] - A[i] for all i < j.
What are the three main steps in a divide and conquer algorithm?
Divide, Recurse, Combine.
In the divide step, how is the array divided?
It is split into two halves: A[l to m] and A[m+1 to u], where m = (l + u) // 2.
What are the three cases considered when combining solutions?
1) Max subarray in left half, 2) Max subarray in right half, 3) Max subarray straddling the midpoint.
How is the straddling case handled in the algorithm?
By computing min in the left half and max in the right half, then taking their difference.
What is the time complexity of the divide and conquer solution?
Theta(n log n)
Why is the divide and conquer approach more efficient?
It reduces the time complexity from quadratic (Theta(n^2)) to near-linear (Theta(n log n)).
What is the main idea behind divide and conquer algorithms?
Divide the problem into subproblems, solve each recursively, and combine their solutions.
What are the three main phases of a divide and conquer algorithm?
Divide, Conquer, Combine
What does the ‘Divide’ step do in divide and conquer?
It splits the problem into smaller subproblems.
What happens in the ‘Conquer’ step of divide and conquer?
Each subproblem is solved, usually recursively.
What is the purpose of the ‘Combine’ step in divide and conquer?
To merge the solutions of subproblems into a solution for the original problem.
What is the time complexity of Merge Sort?
Θ(n log n)
In Merge Sort, which step is most costly in terms of time?
The Combine step, which takes Θ(n) time.
In Quick Sort, where is the majority of the work done?
In the Divide step (partitioning), which takes Θ(n) time.
What is the role of the pivot in Quick Sort?
It is used to partition the array into two subarrays.
What is a method to choose a good pivot in Quick Sort?
The Median of Medians trick.
What is the time complexity of Binary Search?
Θ(log n)
Which step is the most computationally expensive in Binary Search?
None, each step is Θ(1); the recursion provides the efficiency.
What is the Master Method used for?
To analyze the time complexity of divide and conquer algorithms.