Download presentation
Presentation is loading. Please wait.
1
Lecture 27 CSE 331 Nov 4, 2016
2
HW 5 grading and the like
3
HW 7 posted
4
Solutions for HW 6 At the END of the lecture
5
Mergesort algorithm Input: a1, a2, …, an
Output: Numbers in sorted order MergeSort( a, n ) aL = a1,…, an/2 aR = an/2+1,…, an return MERGE ( MergeSort(aL, n/2), MergeSort(aR, n/2) ) If n = 1 return the order a1
6
Inductive step follows from correctness of MERGE
Input: a1, a2, …, an Output: Numbers in sorted order By induction on n MergeSort( a, n ) aL = a1,…, an/2 aR = an/2+1,…, an return MERGE ( MergeSort(aL, n/2), MergeSort(aR, n/2) ) If n = 1 return the order a1 Inductive step follows from correctness of MERGE
7
Rest of today’s agenda Analyze runtime of mergesort algorithm
8
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
9
Improvements on a smaller scale
Greedy algorithms: exponential poly time (Typical) Divide and Conquer: O(n2) asymptotically smaller running time
10
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.