Algorithms: Design and Analysis, Part 1 - Divide & Conquer Algorithms

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Given only the primary key idea for divide and conquer and the inversion problem, what is the high-level algorithm for counting inversions?

Count(array A, length n) -if n = 1 return 0 -else --x = Count(1st half of A, n/2) --y = Count(2nd half of A, n/2) --z = CountSplitInv(A, n) -return x + y + z

What is the running time of the brute-force algorithm for performing matrix multiplication? Why?

O(n³) Addition/multiplication operations take constant time. For result matrix z, z(i,j) = ∑(k = 1...n) x(ik) × y(ik) = O(n). z(i,j) values are calculated n² times.

Given both the primary and secondary key idea for divide and conquer and the inversion problem, what is the revised high-level algorithm for counting inversions?

SortAndCount(array A, length n) -if n = 1 return 0 -else --B, x = SortAndCount(1st half of A, n/2) --C, y = SortAndCount(2nd half of A, n/2) --D, z = MergeAndCountSplitInv(B, C, n) -return x + y + z

Regarding divide and conquer and the inversion problem, what is the primary key idea?

Given an inversion (i, j) with i < j: if i and j are less than n/2, it is a LEFT inversion, can be computed recursively. if i and j > n/2, it is a RIGHT inversion, can be computed recursively. if i <= n/2 < j, it is a SPLIT inversion, must be computed with a separate subroutine.

Regarding divide and conquer and the inversion problem, what is the secondary key idea?

Have recursive calls both count inversions and sort.

What is the running time of the MergeAndCountSplitInv subroutine? Why?

O(n) O(n) for the merge. O(n) for the count of split inversions. O(n) + O(n) = (1 + 1) × O(n) = O(n)

What is the running time of SortAndCount? Why?

O(nlogn) O(logn) levels × O(n) work per level.

What is the running time of a brute-force solution (looping over array A with two indices i, j) to the inversion problem?

O(n²)

Given that X = (A B, C D), Y = (E F, G H), what are the 7 products used in Strausses algorithm?

P₁ = A × (F - H), P₂ = (A + B) × H P₃ = (C + D) × E, P₄ = D × (G - E) P₅ = (A + D) × (E + H) P₆ = (B - D) × (G + H) P₇ = (A - C) × ( E + F)

What is the input and output for the inversion problem?

Input: Array A containing the numbers 1 to n in some arbitrary order. Output: number of inversions = number of pairs (i, j) of array indices with i < j and A[i] > A[j].

If you want to measure the numerical similarity between two ranked list, what problem or method could you use? What measurement would correspond to how similar or dissimilar the lists are?

The inversion problem. The greater the number of inversions, the more dissimilar the lists are.

Regarding the inversion problem and given that left/right conversions can be computed recursively, split inversions cannot be computed recursively (key idea #1) and recursive calls for left/right inversions should sort while counting inversions, what important claim can be made about split inversions?

The split inversions involving an element y of the 2nd array C are precisely the number of uncopied elements left in the 1st array B when y is copied to the output array D.

Given the 7 products of Strausses algorithm, what are the formulas for the four quadrants of X × Y?

(P₅+P₄-P₂+P₆, P₁+P₂) (P₃+P₄, P₁+P₅-P₃-P₇)

What are the general steps for the Divide and Conquer Paradigm?

1) Divide into smaller problems. 2) Conquer via recursive calls. 3) Combine solutions of subproblems into one for the original problem.


Kaugnay na mga set ng pag-aaral

PSYB10 CHAPTER 14 | Altruism and Cooperation

View Set

prepU - perfusion & oxygenation Q's

View Set

ON COURSE Chapter 4 Quiz Questions

View Set

module 7-8 quiz questions .. answers only

View Set