CS 310 Unit 5 Quicksort

# CS 310 Unit 5 Quicksort - CS 310 Unit 5 Quicksort Furman...

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

CS 310 Unit 5 Quicksort Furman Haddix Ph.D. Assistant Professor Minnesota State University,  Mankato

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

View Full Document
CS 310 Unit 5 Quicksort  Objectives Introduction to Quicksort A quicksort Algorithm Quicksort Running Time Randomized quicksort Text, Chapter 7
Introduction to Quicksort Perhaps, pivotsort or partition sort would have  been better names Divide and Conquer algorithm: Divide: Select a pivot, then divide the non- pivot values into subsets based on the pivot  value,  Conquer: Recusively sort the subsets. Combine: No additional work, as quicksort  sorts in place  Expected running time is O(n lg n) Worst case is O(n 2 ), when array is already  sorted, is in inverted sort order, or nearly one of

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

View Full Document
Basic Quicksort Algorithm Problem: Sort the array, A[0 … n-1] quicksort(A, 0, n-1); Pseudocode: quicksort(A, p, q) { if(p < q) { int r = partition(A, p, q); quicksort(A, p, r-1); quicksort(A, r+1, q); } }
Partitioning the  Subarray 5 11 6 12 7 1 8

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 06/09/2008 for the course CS 310 taught by Professor Furmanhaddix during the Spring '08 term at Minnesota State University, Mankato.

### Page1 / 12

CS 310 Unit 5 Quicksort - CS 310 Unit 5 Quicksort Furman...

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

View Full Document
Ask a homework question - tutors are online