LN5 Divide-and conquer Flashcards

1
Q

What is the goal of the Sequence Comparison problem in dynamic programming?

A

To transform one sequence A into another sequence B with the minimum number of edit operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define OPT(i, j) in the context of sequence comparison.

A

OPT(i, j) represents the minimum number of edit steps required to transform the prefix A[1 … i] into B[1 … j].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the three cases for defining OPT(i, j) in sequence comparison?

A
  1. Align last characters: Align a_i and b_j and add mismatch cost delta_ij.
  2. Delete last character of A: Align A[1 … i-1] with B[1 … j] and add a deletion cost.
  3. Insert last character of B: Align A[1 … i] with B[1 … j-1] and add an insertion cost.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the recursive formula for OPT(i, j) in sequence comparison?

A

OPT(i, j) = min{OPT(i-1, j-1) + delta_ij, OPT(i-1, j) + 1, OPT(i, j-1) + 1}.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How is delta_ij defined in the sequence comparison problem?

A

delta_ij equals 1 if a_i does not equal b_j (mismatch), and 0 if a_i equals b_j (match).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the time complexity of solving the sequence comparison problem with dynamic programming?

A

O(n * m), where n and m are the lengths of sequences A and B.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why is backtracking useful in dynamic programming solutions for sequence comparison?

A

Backtracking from OPT(n, m) helps reconstruct the optimal sequence alignment by tracing the choices that minimized edit distance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

For sequences “BOOK” and “BACK,” manually compute the edit distance matrix for practice.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the divide-and-conquer strategy?

A

It is a problem-solving approach that divides a problem into smaller, independent subproblems, solves them recursively, and then combines their solutions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Differentiate between dynamic programming and divide-and-conquer approaches.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the basic recurrence relation for divide-and-conquer time complexity analysis?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain how binary search applies divide-and-conquer principles.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

If you have an unsorted array of integers, why can’t binary search be applied directly?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the skyline problem in algorithm design?

A

Given n rectangles representing buildings, the skyline problem involves computing the upper contour (or union) of these rectangles from a front view.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe the naive approach for solving the skyline problem and its complexity.

A

The naive approach inserts each rectangle individually into an evolving skyline, with an O(n^2) complexity due to repeated updates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How does divide-and-conquer improve the efficiency of solving the skyline problem?

A

By dividing the set of rectangles into two halves, solving for each half, and merging the results, the problem can be solved in O(n log n) time.

17
Q

What is the merge phase in the divide-and-conquer solution to the skyline problem?

A

The merge phase combines two skylines by scanning from left to right and keeping the higher contour at each position.

18
Q

Outline the merge steps for two skyline arrays: [2, 5, 7] and [4, 6, 8].

A

Iterate through both arrays, keeping the higher value at each point. For ties, use the highest point from both arrays.

19
Q

Why are recurrence relations essential for analyzing divide-and-conquer algorithms?

A

Recurrence relations express the time complexity of recursive calls, helping us understand the total complexity of divide-and-conquer solutions.

20
Q

What is the solution to the recurrence T(n) = T(n/2) + O(1)?

A

T(n) = O(log n), applicable to binary search and similar logarithmic time complexity algorithms.

21
Q

How is T(n) = 2T(n/2) + O(n) solved, and what does it represent in algorithm analysis?

A

T(n) = O(n log n), typical for mergesort and skyline problem algorithms.

22
Q

Why is it sometimes beneficial to defer decisions in dynamic programming, as noted in the sequence comparison paradox?

A

Deferring decisions reduces unnecessary complexity by leaving alignment positions open until the global minimum edit distance is calculated.

23
Q

What optimization can be made to the DP matrix in sequence comparison when sequences are similar?

A

Compute only entries close to the main diagonal, as the optimal path likely follows the region with minimal values, reducing unnecessary calculations.

24
Q

Create the recurrence relation and solve it for an algorithm that splits a problem into three parts, each half the size, plus O(n) merge time.

A

The recurrence is T(n) = 3T(n/2) + O(n), which has a solution T(n) = O(n^{log_2 3}) approximately O(n^{1.585}).