algo_ch7_quick_sort

E middle key if a6key 30 a13key 2 and a20key

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: h median (i.e., middle) key If A[6].key = 30, A[13].key = 2, and A[20].key = 10, A[20] becomes the pivot If A[6].key = 3, A[13].key = 2, and A[20].key = 10, A[6] becomes the pivot 14 Choice Of Pivot If A[6].key = 30, A[13].key = 25, and A[20].key = If 10, A[13] becomes the pivot When the pivot is picked at random or when the When median-of-three rule is used, we can use the quicksort code of the textbook provided we first textbook swap the rightmost element and the chosen pivot. swap pivot 15 Partitioning Into Three Groups Sort A = [6, 2, 8, 5, 11, 10, 4, 1, 9, 7, 3]. Sort Leftmost element (6) is the pivot Leftmost When another array B is available: When another Scan A from left to right (omit the pivot in this scan), placing elements ≤ pivot at the left end of B and the remaining elements at the right end of B The pivot is placed at the remaining position of the B 16 Partitioning Example Using Additional Array A 6 2 8 5 11 10 4 1 9 7 3 B 2 5 4 1 3 6 7 9 10 11 8 Sort left and right groups recurs...
View Full Document

This document was uploaded on 11/11/2013.

Ask a homework question - tutors are online