CS 310 Unit 3 Divide and Conquer

CS 310 Unit 3 Divide and Conquer - CS 310 Unit 3 Divide and...

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

View Full Document Right Arrow Icon
CS 310 Unit 3 Divide and Conquer Furman Haddix Ph.D. Assistant Professor Minnesota State University, Mankato
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 310 Unit 3 Divide and Conquer Objectives The divide-and-conquer design paradigm Merge sort Binary search Powering number Fibonacci numbers VLSI tree layout Text, Chapter 2, 3, 4
Background image of page 2
The divide-and-conquer design paradigm Divide – Conquer – Combine Divide the problem (instance) into subproblems. Conquer the subproblems by solving them recursively. Combine subproblem solutions.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Merge Sort Divide and Conquer Successively partition array of elements to be sorted until only 1 (k or less) elements remain. (sort k elements). Successively merge subarrays until all are merged. Divide: Divide each (sub)array into two. Conquer: Recursively sort 2 subarrays. Combine: Linear-time merge.
Background image of page 4
Merge Sort Recurrence Relation Recurrence relations critical questions – What are α , β , and γ ? Divide into α subproblems Each conquer subproblem is of size β There is γ divide and combine processing performed at each step (level) T(n) = α T( β ) + γ α = 2 each step recursively partitions array into two subarrays β = n/2 each subarray is half the size of the previous (sub)array γ = Θ (n) divide is Θ (1) combine is Θ (n)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Solving Merge Sort Recurrence Relation Solving: T(n) = 2T(n/2) + Θ (n) Quick guess: log n levels, each with O(n) processing Substitution Method, Part 1: If true for T(n/2), is it true for T(n)? T(n/2) = O(n/2 log(n/2)) // Don’t care what base log is! T(n) = 2T(n/2) + Θ (n) T(n) = 2O(n/2 log (n/2)) + Θ (n) T(n) = O(n (log n – log2)) T(n) = O(n log n) Substitution Method, Part 2: Is it true for boundary condition Doesn’t work for n = 1, because log(1) = 0 and T(1) = O(1) Try for n = 2
Background image of page 6
Merge Sort/Insertion Sort For large n, merge sort is one of the best algorithms because it is O(n lg n), and fairly predictable in its performance. For comparison sorts, if the number of inversions is large, the number of comparisons required is O(n lg n) inversions are the number of out of order pairs in the set to be sorted However, merge sort does suffer from relatively large constants Although insertion sort is O(n 2 ), it does have relatively small constants, so that for small n, it
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/09/2008 for the course CS 310 taught by Professor Furmanhaddix during the Spring '08 term at Minnesota State University, Mankato.

Page1 / 27

CS 310 Unit 3 Divide and Conquer - CS 310 Unit 3 Divide and...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online