Download presentation
Presentation is loading. Please wait.
1
Lecture 30 CSE 331 Nov 12, 2012
2
Another feedback Writing up the solutions takes disproportionately long! Yes, writing well is very hard to do
3
Mergesort algorithm Input: a1, a2, …, an
Output: Numbers in sorted order MergeSort( a, n ) If n = 1 return the order a1 aL = a1,…, a[n/2] aR = a[n/2]+1,…, an return MERGE ( MergeSort(aL, [n/2]), MergeSort(aR, n-[n/2]) ) If n = 2 return the order min(a1,a2); max(a1,a2)
4
Inductive step follows from correctness of MERGE
Input: a1, a2, …, an Output: Numbers in sorted order By induction on n MergeSort( a, n ) If n = 2 return the order min(a1,a2); max(a1,a2) aL = a1,…, a[n/2] aR = a[n/2]+1,…, an return MERGE ( MergeSort(aL, [n/2]), MergeSort(aR, n-[n/2]) ) If n = 1 return the order a1 Inductive step follows from correctness of MERGE
5
Run time recurrence T(n) ≤ c if n ≤ 2 2*T(n/2) + c*n otherwise
6
Today’s agenda Solve the recurrence Multiplying two integers
7
Divide and Conquer Divide up the problem into at least two sub-problems Recursively solve the sub-problems “Patch up” the solutions to the sub-problems for the final solution
8
Improvements on a smaller scale
Greedy algorithms: exponential poly time (Typical) Divide and Conquer: O(n2) asymptotically smaller running time
9
Multiplying two numbers
Given two numbers a and b in binary a=(an-1,..,a0) and b = (bn-1,…,b0) Running time of primary school algorithm? Compute c = a x b
10
The current algorithm scheme
Shift by O(n) bits Adding O(n) bit numbers Mult over n bits a b = a1b1 22[n/2] + (a1b0+a0b1)2[n/2] + a0b0 Multiplication over n/2 bit inputs T(n) is O(n2) T(n) ≤ 4T(n/2) + cn T(1) ≤ c
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.