0% found this document useful (0 votes)
25 views

Quick Sort

The document describes the quicksort algorithm sorting a list of numbers. It shows the steps of selecting a pivot number, dividing the list into numbers smaller and larger than the pivot, and recursively applying the same process to the sublists until individual numbers remain, resulting in a fully sorted list.

Uploaded by

Nadien DieSya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Quick Sort

The document describes the quicksort algorithm sorting a list of numbers. It shows the steps of selecting a pivot number, dividing the list into numbers smaller and larger than the pivot, and recursively applying the same process to the sublists until individual numbers remain, resulting in a fully sorted list.

Uploaded by

Nadien DieSya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 7

QuickSort Example

13, 21, 15, 3, 12, 9, 14, 7, 6 3, 9, 7, 6,


21 3 < 12 12 so so we we do dont write write it down it down We ignore the pivot for and move on. 13 15 14 7 6 <> > 12 12 so so we we do dont write write it the down it moment down First we number in the centre of the list as a pivot. We then divide the 9 < 12 souse we the do write it down. list into those that are smaller than the pivot and those that are larger. First we write a list of the numbers smaller than the pivot.

QuickSort Example
13, 21, 15, 3, 12, 9, 14, 7, 6 15 14 3, 9, 7, 6, 12, 13, 21, 15,
We have down all again the numbers less than the pivot. Nowgreater we canthan write We now go written through the list and write down all the numbers the pivot. down the pivot in its correct position.

QuickSort Example
13, 21, 15, 3, 12, 9, 14, 7, 6 3, 9, 7, 6, 12, 13, 21, 15, 14 3, 6, 7, 9,
We now repeat the procedure on the first half of the list. First we write select a pivot. take We write Now we down down the numbers the We pivot. Now thethan numbers greater than 7. the number 77to the right of centre. smaller

QuickSort Example
13, 21, 15, 3, 12, 9, 14, 7, 6 3, 9, 7, 6, 12, 13, 21, 15, 14 3, 6, 7, 9, 12 13, 14, 15, 21
Moving on to the second half.

We take the number 15 to the right of centre as the pivot. We Now write we down down thegreater numbers the pivot. Now the write numbers than 15. smaller than 15

QuickSort Example
13, 3, 3, 3, 21, 9, 6, 6, 15, 7, 7, 7, 3, 12, 9, 14, 7, 6 6, 12, 13, 21, 15, 14 9, 12, 13, 14, 15, 21 9

The list is now sorted but the algorithm keeps going until lists of length 1 are reached. Less Moving Nowlist than the on pivot. pivot. 9 is a list First has pivot 6. on its own.

QuickSort Example
13, 3, 3, 3, 21, 9, 6, 6, 15, 7, 7, 7, 3, 6, 9, 9, 12, 12, 12, 12, 9, 14, 13, 21, 13, 14, 13, 14, 7, 6 15, 14 15, 21 15, 21

The next list is easily Finally dealtthe with. last list.

QuickSort Example
13, 3, 3, 3, 3, 21, 9, 6, 6, 6, 15, 7, 7, 7, 7, 3, 6, 9, 9, 9, 12, 12, 12, 12, 12, 9, 14, 13, 21, 13, 14, 13, 14, 13, 14, 7, 6 15, 14 15, 21 15, 21 15, 21

Only two lists of length one remain to be dealt with.

The algorithm finishes when all the numbers have been considered as pivots.

You might also like