MergeSort

# MergeSort - Merge Sort 4/1/2003 8:46 AM Outline and Reading

This preview shows pages 1–2. Sign up to view the full content.

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 (§10.1.1) Merge-sort (§10.1) ± Algorithm ± Merging two sorted sequences ± Merge-sort tree ± Execution example ± Analysis Generic merging and set operations (§10.2) Summary of sorting algorithms 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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue.

### Page1 / 3

MergeSort - Merge Sort 4/1/2003 8:46 AM Outline and Reading

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

View Full Document
Ask a homework question - tutors are online