notes96 - Merge sort Complexity Each element is copied a...

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

View Full Document Right Arrow Icon
Merge sort Complexity Each element is copied a number of times proportional to the height of the tree. height = log n Hence, n elements are copied a number of times proportional to n log n Merge sort complexity is O ( n log n) Quick Sort Popular sorting algorithm that also uses divide and conquer. void quicksort(S) Input: unsorted array S Output : sorted array S 1. Divide If S has only 1 element then return else{ - choose an element X in S that we will call pivot - Divide S into 3 sets L, E, G where the elements in L are less than X the elements in G are greater than X the elements in E are equal to X 2. Recur quicksort(L) quicksort(G) 3. Conquer put elements of L, E, G back into S Eg: quicksort(7, 6, 2, 10, 4, 5, 9, 8) pivot L E G qs(7, 6, 2, 4, 5) 8 qs(10, 9) L E
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
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 University-West Lafayette.

Page1 / 6

notes96 - Merge sort Complexity Each element is copied a...

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

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