Presentation is loading. Please wait.

Presentation is loading. Please wait.

QuickSort Example Use the first number in the list as a ‘pivot’. 13211591231476 First write a list of the numbers smaller than the pivot, in the order.

Similar presentations


Presentation on theme: "QuickSort Example Use the first number in the list as a ‘pivot’. 13211591231476 First write a list of the numbers smaller than the pivot, in the order."— Presentation transcript:

1

2 QuickSort Example Use the first number in the list as a ‘pivot’. 13211591231476 First write a list of the numbers smaller than the pivot, in the order in which they appear in the original list. Divide the list into two sub-lists: those that are smaller than the pivot and those that are larger, as follows: 912376 9 376

3 QuickSort Example Use the first number in the list as a ‘pivot’. 13211591231476 Next, write down the pivot in its correct position. Divide the list into two sub-lists: those that are smaller than the pivot and those that are larger, as follows: 912376 9 37613

4 21 QuickSort Example Use the first number in the list as a ‘pivot’. 13211591231476 Next, write down the numbers larger than the pivot, in the order in which they appear in the original list. Divide the list into two sub-lists: those that are smaller than the pivot and those that are larger, as follows: 912376 9 37613 2115 14

5 21 QuickSort Example The pivot, 13, is now in its correct position. The next step is to apply the same procedure as before to each of the sub-lists. 13211591231476 Write down the numbers smaller than the pivot, in the order in which they appear in the original sub-list. Start with the first sub-list, and use the first number in the sub-list as a pivot. 9123761315143 3 7 7 6 613

6 21 QuickSort Example 13211591231476 Then write down the pivot. 9123761315143 3 7 7 6 6913 The pivot, 13, is now in its correct position. The next step is to apply the same procedure as before to each of the sub-lists. Start with the first sub-list, and use the first number in the sub-list as a pivot.

7 21 QuickSort Example 13211591231476 Then write down the numbers in the sub-list which are greater than the pivot, in the order in which they appear in the original sub-list. 9123761315143 3 7 7 6 69 12 13 The pivot, 13, is now in its correct position. The next step is to apply the same procedure as before to each of the sub-lists. Start with the first sub-list, and use the first number in the sub-list as a pivot.

8 21 QuickSort Example 13211591231476 912376131514 37691213 The pivot, 13, is now in its correct position. The next step is to apply the same procedure as before to each of the sub-lists. Now look at the second sub-list, and use the first number in the sub-list as a pivot. Write down the numbers smaller than the pivot, in the order in which they appear in the original sub-list. 15 14

9 21 QuickSort Example 13211591231476 912376131514 37691213 The pivot, 13, is now in its correct position. The next step is to apply the same procedure as before to each of the sub-lists. Now look at the second sub-list, and use the first number in the sub-list as a pivot. 15 14 Then write down the pivot. 14 21 In this case there are no numbers greater than the pivot.

10 21 QuickSort Example 13211591231476 912376131514 37691213 The numbers 9, 12, 13 and 21 are now in the correct positions. The next step is to apply the same procedure to any sub-lists containing more than one number. Look at the first sub-list, and use the first number in the sub-list as a pivot. 151421 9121321 There are no numbers smaller than the pivot, so write down the pivot. 3

11 21 QuickSort Example 13211591231476 912376131514 37691213 The numbers 9, 12, 13 and 21 are now in the correct positions. The next step is to apply the same procedure to any sub-lists containing more than one number. Look at the first sub-list, and use the first number in the sub-list as a pivot. 151421 91213213 Then write down the numbers in the sub-list which are greater than the pivot, in the order in which they appear in the original sub-list. 7 76 6

12 21 QuickSort Example 13211591231476 912376131514 37691213 The numbers 9, 12, 13 and 21 are now in the correct positions. The next step is to apply the same procedure to any sub-lists containing more than one number. 151421 9121321376 Now look at the second sub-list, and use the first number in the sub-list as a pivot. 14 Write down the numbers smaller than the pivot, in the order in which they appear in the original sub-list.

13 21 QuickSort Example 13211591231476 912376131514 37691213 The numbers 9, 12, 13 and 21 are now in the correct positions. The next step is to apply the same procedure to any sub-lists containing more than one number. 151421 9121321376 Now look at the second sub-list, and use the first number in the sub-list as a pivot. 14 Then write down the pivot. In this case there are no numbers greater than the pivot. 15

14 21 QuickSort Example 13211591231476 912376131514 37691213 There is now just one sub-list containing more than one number. 151421 9121321376 Use the first number in the sub-list as a pivot. 1415 912132131415 Write down the numbers smaller than the pivot, in the order in which they appear in the original sub-list. 6 6

15 21 QuickSort Example 13211591231476 912376131514 37691213 There is now just one sub-list containing more than one number. 151421 9121321376 Use the first number in the sub-list as a pivot. 1415 912132131415 Then write down the pivot. 6 67

16 21 QuickSort Example 13211591231476 912376131514 37691213 There are now no sub-lists containing more than one number, so the list is sorted. 151421 91213213761415 91213213141567

17 22, 26,14,20,12,9,11,15,10

18 Quick sort animation The Simpsons http://www.youtube.com/watch?v=MtcrEhrt_K0 Lego bubblesort


Download ppt "QuickSort Example Use the first number in the list as a ‘pivot’. 13211591231476 First write a list of the numbers smaller than the pivot, in the order."

Similar presentations


Ads by Google