MergeSort-handouts-2

MergeSort-handouts-2 - Merge Sort 1/25/2006 11:16 PM Merge...

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

View Full Document Right Arrow Icon
Merge Sort 1/25/2006 11:16 PM 1 Merge Sort 1 Merge Sort 7 2 9 4 2 4 7 9 7 2 2 7 9 4 4 9 7 7 2 2 9 9 4 4 Merge Sort 2 Outline and Reading Divide-and-conquer paradigm (§4.1.1) Merge-sort (§4.1.1) ± Algorithm ± Merging two sorted sequences ± Merge-sort tree ± Execution example ± Analysis Generic merging and set operations (§4.2.1) Summary of sorting algorithms (§4.2.1)
Background image of page 1

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

View Full DocumentRight Arrow Icon
1/25/2006 11:16 PM 2 Merge Sort 3 Divide-and-Conquer Divide-and conquer is a general algorithm design paradigm: ± Divide : divide the input data S in two disjoint subsets S 1 and S 2 ± Recur : solve the subproblems associated with S 1 and S 2 ± Conquer : combine the solutions for S 1 and S 2 into a solution for S The base case for the recursion are subproblems of size 0 or 1 Merge-sort is a sorting algorithm based on the divide-and-conquer paradigm Like heap-sort ± It uses a comparator ± It has O ( n log n ) running time Unlike heap-sort ± It does not use an auxiliary priority queue ± It accesses data in a sequential manner (suitable to sort data on a disk) Merge Sort 4 Merge-Sort Merge-sort on an input sequence S with n elements consists of three steps: ± Divide : partition S into two sequences S 1 and S 2 of about n / 2 elements each ± Recur : recursively sort S 1 and S 2 ± Conquer : merge S 1 and S 2 into a unique sorted sequence Algorithm mergeSort ( S, C ) Input sequence S with n elements, comparator C Output sequence S sorted according to C if S.size () > 1 ( S 1 , S 2 ) partition
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

MergeSort-handouts-2 - Merge Sort 1/25/2006 11:16 PM Merge...

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

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