![Page 1: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/1.jpg)
QuickSort
QuickSort is often called Partition Sort.
It is a recursive method, in which the unsorted array is first rearranged so that there is some record, somewhere in the middle of the array, whose key is greater than all the keys to its left & less than or equal to all the keys to its right.
Once this “middle is found, the same method can be used to sort the section of the array to the left, then sort the section to the right.
![Page 2: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/2.jpg)
QuickSort Algorithm
1. If First < Last then 2. Partition the elements in the array (First, Last) so that the pivot value is in place ( position PivIndex). 3. Apply QuickSort to the first subarray (First, PivIndex -1) 4. Apply QuickSort to the second subarray (PivIndex + 1, Last).
The two stopping Cases are: 1. (First = Last) - only one value in subarray, so sorted. 2. (First > Last) - no values in subarray, so sorted.
![Page 3: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/3.jpg)
How do we Partition?
1. Define the pivot value as the content of Table[First]2. Initialize Up to First and Down to last3. Repeat 4. Increment Up until Up selects the first element greater than the pivot value 5. Decrement Down until it selects the first element less than or equal to the pivot value. 6. If Up < Down exchange their values.
Until Up meets or passes Down.
7. Exchange Table[First] and Table[Down]8. Define PivIndex as Down
![Page 4: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/4.jpg)
QuickSort Example
44 75 23 64 331243 7755
0 1 2 3 4 5 6 7 8
First Last
Has First exceeded Last? No!
Pivot 44
Define the value in position First to be the Pivot.
![Page 5: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/5.jpg)
QuickSort Example
44 75 23 64 331243 7755
0 1 2 3 4 5 6 7 8
First Last
Pivot 44
Define Up To be First and Down to be last
Up Down
![Page 6: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/6.jpg)
QuickSort Example
44 75 23 64 331243 7755
0 1 2 3 4 5 6 7 8
First Last
Pivot 44
Move Up to the first value > Pivot
Up Down
![Page 7: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/7.jpg)
QuickSort Example
44 75 23 64 331243 7755
0 1 2 3 4 5 6 7 8
First Last
Pivot 44
Move Down to the first value <= Pivot
Up Down
![Page 8: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/8.jpg)
QuickSort Example
44 33 23 64 751243 7755
0 1 2 3 4 5 6 7 8
First Last
Pivot 44
If Up < Down, exchange their values
Up Down
![Page 9: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/9.jpg)
QuickSort Example
44 33 23 64 751243 7755
0 1 2 3 4 5 6 7 8
First Last
Pivot 44
Move Up to the first value > Pivot
UpDown
![Page 10: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/10.jpg)
QuickSort Example
44 33 23 64 751243 7755
0 1 2 3 4 5 6 7 8
First Last
Pivot 44
Move Down to the first value <= Pivot
Up Down
![Page 11: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/11.jpg)
QuickSort Example
44 33 23 64 755543 7712
0 1 2 3 4 5 6 7 8
First Last
Pivot 44
If Up < Down, exchange their values.
Up Down
![Page 12: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/12.jpg)
QuickSort Example
44 33 23 64 755543 7712
0 1 2 3 4 5 6 7 8
First Last
Pivot 44
Move Up to the first value > Pivot
Up Down
![Page 13: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/13.jpg)
QuickSort Example
44 33 23 64 755543 7712
0 1 2 3 4 5 6 7 8
First Last
Pivot 44
Move Down to the first value <= Pivot
Up Down
Up and Down have passed each other, so exchange the pivot value and the value in Down.
![Page 14: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/14.jpg)
QuickSort Example
12 33 23 64 755543 7744
0 1 2 3 4 5 6 7 8
First Last
Pivot 44
Up Down
Up and Down have passed each other, so exchange the pivot value and the value in Down.
![Page 15: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/15.jpg)
QuickSort Example
12 33 23 64 755543 7744
0 1 2 3 4 5 6 7 8
First Last
Pivot 44
PivIndex
Note that all values below PivIndex are <= Pivot andall values above PivIndex are > Pivot.
![Page 16: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/16.jpg)
QuickSort Example
12 33 23 64 755543 7744
0 1 2 3 4 5 6 7 8
First1 Last2
Pivot 44
PivIndex
This gives us two new subarrays to Partition
Last1First2
![Page 17: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/17.jpg)
QuickSort Procedure Code
void QuickSort(int Table[], int First, int Last){ int PivIndex; if (First < Last) { PivIndex = Partition(Table, First, Last); QuickSort(Table, First, PivIndex - 1); QuickSort(Table, PivIndex + 1, Last); }}
![Page 18: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/18.jpg)
Heap Sort
How can a tree be represented in an array?
0 1 2 3 4 5 6
12
57 19
87 15 44 23
![Page 19: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/19.jpg)
Heap Sort
How can a tree be represented in an array?
12
0 1 2 3 4 5 6
12
57 19
87 15 44 23
Place the root of the tree in element 0 of the array (RootPos = 0).
![Page 20: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/20.jpg)
Heap Sort
How can a tree be represented in an array?
12 57 19
0 1 2 3 4 5 6
12
57 19
87 15 44 23
Place the root of the tree in element 0 of the array (RootPos = 0).Place the root’s left child in element 1 : (RootPos*2 + 1) = 1Place the root’s right child in element 2: (RootPos*2 + 2) = 2
![Page 21: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/21.jpg)
Heap SortHow can a tree be represented in an array?
12 57 19 87 15
0 1 2 3 4 5 6
12
57 19
87 15 44 23
Place the root of the tree in element 0 of the array (RootPos = 0).Place the root’s left child in element 1 : (RootPos*2 + 1)Place the root’s right child in element 2: (RootPos*2 + 2)
The Children of 57 are placed in:Left Child (87): ParentPos*2 +1 = 1* 2 + 1 = 3Right Child (15): ParentPos*2 + 2 = 1 *2 + 2 = 4
![Page 22: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/22.jpg)
Heap SortHow can a tree be represented in an array?
12 57 19 87 15
0 1 2 3 4 5 6
12
57 19
87 15 44 23
Place the root of the tree in element 0 of the array (RootPos = 0).Place the root’s left child in element 1 : (RootPos*2 + 1)Place the root’s right child in element 2: (RootPos*2 + 2)
The Children of 19 are placed in:Left Child (44): ParentPos*2 +1 = 2* 2 + 1 = 5Right Child (15): ParentPos*2 + 2 = 2 *2 + 2 = 6
44 23
![Page 23: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/23.jpg)
Heap Sort
To perform the heap sort we must:
1. Create a heap (a tree with all nodes greater than their children)
2. Remove the root element from the heap one at a time, recomposing the heap.
![Page 24: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/24.jpg)
Building the Heap
1. For each value in the array(0, n)
2. Place the value into the “tree” 3. Bubble the value as high as it can go (push the largest values to highest position)
![Page 25: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/25.jpg)
Heap SortHow to build a heap?
12 57 19 87 15
0 1 2 3 4 5 6
12
Add Table[0] to treeSince it has no parent, we have a heap.
44 23
![Page 26: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/26.jpg)
Heap SortHow to build a heap?
12 57 19 87 15
0 1 2 3 4 5 6
12
Add Table[1] to treeSince 12 < 57, it is not a heap.Bubble it up as high as it can go. Exchange
44 23
57
![Page 27: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/27.jpg)
Heap SortHow to build a heap?
57 12 19 87 15
0 1 2 3 4 5 6
57
ExchangeSince 57 >12 57 is as high as it can go, so we have a heap.
44 23
12
![Page 28: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/28.jpg)
Heap SortHow to build a heap?
57 12 19 87 15
0 1 2 3 4 5 6
57
Add Table[2] to treeSince 57 >19 so, we have a heap.
44 23
12 19
![Page 29: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/29.jpg)
Heap SortHow to build a heap?
57 12 19 87 15
0 1 2 3 4 5 6
57
Add Table[3] to treeSince 87 >12 so, not a heap.
44 23
12 19
87
![Page 30: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/30.jpg)
Heap SortHow to build a heap?
57 87 19 12 15
0 1 2 3 4 5 6
57
Add Table[3] to treeSince 87 >12 so, not a heap. Bubble it up. Exchange.Again 87 > 57, so not a heap. Bubble it up
44 23
87 19
12
![Page 31: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/31.jpg)
Heap SortHow to build a heap?
87 57 19 12 15
0 1 2 3 4 5 6
87
Again 87 > 57, so not a heap. Bubble it up.Exchange.We now have a heap again.
44 23
57 19
12
![Page 32: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/32.jpg)
Heap SortHow to build a heap?
87 57 19 12 15
0 1 2 3 4 5 6
87
Add Table[4] to tree15 > 57, so a heap.
44 23
57 19
12 15
![Page 33: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/33.jpg)
Heap SortHow to build a heap?
87 57 19 12 15
0 1 2 3 4 5 6
87
Add Table[5] to tree44 > 19, so not a heap.
44 23
57 19
12 15 44
![Page 34: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/34.jpg)
Heap SortHow to build a heap?
87 57 44 12 15
0 1 2 3 4 5 6
87
44 > 19, so not a heap. Bubble it up. Exchange.44<87Again we have a heap.
19 23
57 44
12 15 19
![Page 35: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/35.jpg)
Heap SortHow to build a heap?
87 57 44 12 15
0 1 2 3 4 5 6
87
Add Table[6] to tree23 <44 so, we have a heap.
19 23
57 44
12 15 19 23
![Page 36: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/36.jpg)
Heap SortHow to build a heap?
87 57 44 12 15
0 1 2 3 4 5 6
87
The whole table is now a heap!
23
57 44
12 15 19 23
19
![Page 37: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/37.jpg)
Heap Sort Algorithm
1. Repeat n -1 times 2. Exchange the root value with the last value in the tree 3. “Drop” the last value from the tree 4. Reform the heap 5. Start at the root node of the current tree 6. If the root is larger than its children, stop- you have a heap. 7. If not, exchange the root with the largest child. 8. Consider this child to be the current root and repeat step 4
![Page 38: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/38.jpg)
Heap Sort
87 57 44 12 15
0 1 2 3 4 5 6
87
Here is the heap!
19 23
57 44
12 15 19 23
![Page 39: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/39.jpg)
Heap Sort
87 57 44 12 15
0 1 2 3 4 5 6
87
Exchange the root with the last value in the tree
19 23
57 44
12 15 19 23
![Page 40: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/40.jpg)
Heap Sort
23 57 44 12 15
0 1 2 3 4 5 6
23
Exchange the root with the last value in the tree
19 87
57 44
12 15 19 87
![Page 41: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/41.jpg)
Heap Sort
23 57 44 12 15
0 1 2 3 4 5 6
23
Drop this last value from the tree -- it is now in the array in its sorted position!
19 87
57 44
12 15 19 87
![Page 42: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/42.jpg)
Heap Sort
23 57 44 12 15
0 1 2 3 4 5 6
23
Drop this last value from the tree -- it is now in the array in its sorted position!
19 87
57 44
12 15 19
The sorted listThe tree
![Page 43: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/43.jpg)
Heap Sort
23 57 44 12 15
0 1 2 3 4 5 6
23
Reform the heap
19 87
57 44
12 15 19
The sorted listThe tree
![Page 44: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/44.jpg)
Heap Sort
23 57 44 12 15
0 1 2 3 4 5 6
23
Find the largest child of the current “root”and exchange with “root”
19 87
57 44
12 15 19
The sorted listThe tree
![Page 45: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/45.jpg)
Heap Sort
57 23 44 12 15
0 1 2 3 4 5 6
57
Now 23 is larger than both of its children so we have a heap again.
19 87
23 44
12 15 19
The sorted listThe tree
![Page 46: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/46.jpg)
Heap Sort
57 23 44 12 15
0 1 2 3 4 5 6
57
Exchange the root of the heap with the last value in the tree.
19 87
23 44
12 15 19
The sorted listThe tree
![Page 47: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/47.jpg)
Heap Sort
19 23 44 12 15
0 1 2 3 4 5 6
19
Exchange the root of the heap with the last value in the tree.
57 87
23 44
12 15 57
The sorted listThe tree
![Page 48: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/48.jpg)
Heap Sort
19 23 44 12 15
0 1 2 3 4 5 6
19
Drop the last element from the tree since the value is nowin its sorted position.
57 87
23 44
12 15 57
The sorted listThe tree
![Page 49: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/49.jpg)
Heap Sort
19 23 44 12 15
0 1 2 3 4 5 6
19
Drop the last element from the tree since the value is nowin its sorted position.
57 87
23 44
12 15
The sorted listThe tree
![Page 50: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/50.jpg)
Heap Sort
19 23 44 12 15
0 1 2 3 4 5 6
19
Reform the heap
57 87
23 44
12 15
The sorted listThe tree
![Page 51: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/51.jpg)
Heap Sort
19 23 44 12 15
0 1 2 3 4 5 6
19
Find the largest child of the current “root”.Exchange the values.
57 87
23 44
12 15
The sorted listThe tree
![Page 52: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/52.jpg)
Heap Sort
44 23 19 12 15
0 1 2 3 4 5 6
44
Since 19 has no children, we now have a heap again.
57 87
23 19
12 15
The sorted listThe tree
![Page 53: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/53.jpg)
Heap Sort
44 23 19 12 15
0 1 2 3 4 5 6
44
Swap the root with the last position in the tree.
57 87
23 19
12 15
The sorted listThe tree
![Page 54: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/54.jpg)
Heap Sort
15 23 19 12 44
0 1 2 3 4 5 6
15
Drop the last value from the tree.
57 87
23 19
12
The sorted listThe tree
44
![Page 55: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/55.jpg)
Heap Sort
15 23 19 12 44
0 1 2 3 4 5 6
15
Drop the last value from the tree.
57 87
23 19
12
The sorted listThe tree
![Page 56: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/56.jpg)
Heap Sort
15 23 19 12 44
0 1 2 3 4 5 6
15
Reform the heap by exchanging the root with its largest child
57 87
23 19
12
The sorted listThe tree
![Page 57: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/57.jpg)
Heap Sort
23 15 19 12 44
0 1 2 3 4 5 6
23
Reform the heap by exchanging the root with its largest child
57 87
15 19
12
The sorted listThe tree
![Page 58: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/58.jpg)
Heap Sort
23 15 19 12 44
0 1 2 3 4 5 6
23
Exchange the root with the last value in the tree
57 87
15 19
12
The sorted listThe tree
![Page 59: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/59.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Exchange the root with the last value in the tree
57 87
15 19
23
The sorted listThe tree
![Page 60: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/60.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Drop the last value from the tree
57 87
15 19
23
The sorted listThe tree
![Page 61: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/61.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Drop the last value from the tree
57 87
15 19
The sorted listThe tree
![Page 62: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/62.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Reform the heap
57 87
15 19
The sorted listThe tree
![Page 63: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/63.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Exchange the root with the largest child
57 87
15 19
The sorted listThe tree
![Page 64: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/64.jpg)
Heap Sort
19 15 12 23 44
0 1 2 3 4 5 6
19
We have a heap
57 87
15 12
The sorted listThe tree
![Page 65: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/65.jpg)
Heap Sort
19 15 12 23 44
0 1 2 3 4 5 6
19
Exchange the root with the last position in the tree
57 87
15 12
The sorted listThe tree
![Page 66: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/66.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Exchange the root with the last position in the tree
57 87
15 19The sorted list
The tree
![Page 67: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/67.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Drop the last value from the tree
57 87
15 19The sorted list
The tree
![Page 68: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/68.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Drop the last value from the tree
57 87
15
The sorted listThe tree
![Page 69: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/69.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Reform the heap
57 87
15
The sorted listThe tree
![Page 70: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/70.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Exchange the root with the largest child
57 87
15
The sorted listThe tree
![Page 71: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/71.jpg)
Heap Sort
15 12 19 23 44
0 1 2 3 4 5 6
15
We have a heap
57 87
12
The sorted listThe tree
![Page 72: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/72.jpg)
Heap Sort
15 12 19 23 44
0 1 2 3 4 5 6
15
Exchange the root with the last value in the tree
57 87
12
The sorted listThe tree
![Page 73: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/73.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Exchange the root with the last value in the tree
57 87
15
The sorted listThe tree
![Page 74: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/74.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Drop the last value from the tree
57 87
15
The sorted listThe tree
![Page 75: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/75.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
Drop the last value from the tree
57 87
The sorted listThe tree
![Page 76: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/76.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
12
The tree consists of a single value at this point which is in its proper place within the sorted list.
57 87
The sorted listThe tree
![Page 77: QuickSort QuickSort is often called Partition Sort. It is a recursive method, in which the unsorted array is first rearranged so that there is some record,](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d5d5503460f94a3ba1d/html5/thumbnails/77.jpg)
Heap Sort
12 15 19 23 44
0 1 2 3 4 5 6
The tree consists of a single value at this point which is in its proper place within the sorted list.The array is sorted.
57 87
The sorted listThe tree