{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

E middle key if a6key 30 a13key 2 and a20key

Info icon This 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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern