LN5 Divide-and conquer Flashcards
What is the goal of the Sequence Comparison problem in dynamic programming?
To transform one sequence A into another sequence B with the minimum number of edit operations.
Define OPT(i, j) in the context of sequence comparison.
OPT(i, j) represents the minimum number of edit steps required to transform the prefix A[1 … i] into B[1 … j].
What are the three cases for defining OPT(i, j) in sequence comparison?
- Align last characters: Align a_i and b_j and add mismatch cost delta_ij.
- Delete last character of A: Align A[1 … i-1] with B[1 … j] and add a deletion cost.
- Insert last character of B: Align A[1 … i] with B[1 … j-1] and add an insertion cost.
What is the recursive formula for OPT(i, j) in sequence comparison?
OPT(i, j) = min{OPT(i-1, j-1) + delta_ij, OPT(i-1, j) + 1, OPT(i, j-1) + 1}.
How is delta_ij defined in the sequence comparison problem?
delta_ij equals 1 if a_i does not equal b_j (mismatch), and 0 if a_i equals b_j (match).
What is the time complexity of solving the sequence comparison problem with dynamic programming?
O(n * m), where n and m are the lengths of sequences A and B.
Why is backtracking useful in dynamic programming solutions for sequence comparison?
Backtracking from OPT(n, m) helps reconstruct the optimal sequence alignment by tracing the choices that minimized edit distance.
For sequences “BOOK” and “BACK,” manually compute the edit distance matrix for practice.
Use the recursive formula and initialize with OPT(i, 0) = i and OPT(0, j) = j. Fill out the matrix row by row, using the three cases at each step.
What is the divide-and-conquer strategy?
It is a problem-solving approach that divides a problem into smaller, independent subproblems, solves them recursively, and then combines their solutions.
Differentiate between dynamic programming and divide-and-conquer approaches.
Dynamic programming solves overlapping subproblems with memoization to avoid redundant work. Divide-and-conquer splits problems into independent subproblems and does not reuse subproblem solutions.
What is the basic recurrence relation for divide-and-conquer time complexity analysis?
T(n) = 2T(n/2) + O(n), which often simplifies to T(n) = O(n log n) for problems like mergesort and the skyline problem.
Explain how binary search applies divide-and-conquer principles.
Binary search divides a sorted array in half with each comparison, recursively reducing the search space by half until the element is found or the array cannot be divided further.
If you have an unsorted array of integers, why can’t binary search be applied directly?
Binary search relies on a sorted array, allowing comparisons to eliminate half of the remaining elements. In an unsorted array, binary search is ineffective because there is no guaranteed order.
What is the skyline problem in algorithm design?
Given n rectangles representing buildings, the skyline problem involves computing the upper contour (or union) of these rectangles from a front view.
Describe the naive approach for solving the skyline problem and its complexity.
The naive approach inserts each rectangle individually into an evolving skyline, with an O(n^2) complexity due to repeated updates.