{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cse101-w12-dq1-tablet

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full Document Right Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full Document Right Arrow Icon
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
Background image of page 4
(Unhelpful) DQ for Integer Multiplication Can we apply D/Q?
Background image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}