{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cse101-w12-dq1-tablet

# cse101-w12-dq1-tablet - Divide and Conquer(DQ First...

This preview shows pages 1–6. Sign up to view the full content.

Divide and Conquer (“DQ”) First “paradigm” or “framework” DQ(S) if S is small return ADHOC(S) else decompose S into subproblems S 1 ,…, S k // divide for i = 1 to k do y i = DQ(S i ) // conquer recombine y i into solution y // compose return y “Universal method”: Mergesort, Quicksort, FFT, Matrix/Integer arithmetic are classic examples

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
DQ for Sorting Divide (into two equal parts) Conquer (solve for each part separately) Combine separate solutions • Mergesort – Divide into two equal parts – Sort each part using Mergesort (recursion!!!) – Merge two sorted subsequences
Merging Two Subsequences Sequence #1: x[1]-x[2]- … - x[k] Sequence #2: y[1]-y[2]- … - y[l] if y[i] < x[j] compare y[i+1] and x[j] < k+l-1 edges = # (comparisons) = linear time 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Tree of Recursions in Mergesort 1 2 3 4 5 6 7 8 1 3 5 8 2 4 6 7 1 5 3 8 5 1 8 3 4 7 2 6 7 4 6 2 log n n comparisons per level log n levels total runtime = n log n
(Unhelpful) DQ for Integer Multiplication Can we apply D/Q?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}