quicksort: illustrated step-by-step walk through
DESCRIPTION
A step-by-step illustration of Quicksort to help you walk through a series of operations. Illustration is accompanied by actual code with bold line indicating the current operation.TRANSCRIPT
![Page 1: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/1.jpg)
Quicksort algorithmIllustrated walkthrough
![Page 2: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/2.jpg)
Partition function
This function does the most of the heavy lifting, so we look at it first, then see it in the context of Quicksort algorithm
![Page 3: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/3.jpg)
12 7 14 9 10 11
[0]
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
[1] [2] [3] [4] [5]
![Page 4: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/4.jpg)
12 7 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
istore Index
![Page 5: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/5.jpg)
12 7 14 9 10 11
begin last
0
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
store Index
i
![Page 6: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/6.jpg)
12 7 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
0store Index
0i
![Page 7: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/7.jpg)
12 7 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
0store Index
0i
0 < 5is true
![Page 8: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/8.jpg)
12 7 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
0store Index
0i
12 <= 11is false
![Page 9: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/9.jpg)
12 7 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
0store Index
1i
![Page 10: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/10.jpg)
12 7 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
0store Index
1i
7 <= 11is true
![Page 11: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/11.jpg)
12 7 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
0store Index
1i
Swap
![Page 12: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/12.jpg)
7 12 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
0store Index
1i
Swap
![Page 13: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/13.jpg)
7 12 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
1store Index
1i
![Page 14: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/14.jpg)
7 12 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
1store Index
2i
![Page 15: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/15.jpg)
7 12 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
1store Index
2i
2 < 5is true
![Page 16: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/16.jpg)
7 12 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
1store Index
2i
14 <= 11is fase
![Page 17: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/17.jpg)
7 12 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
1store Index
3i
![Page 18: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/18.jpg)
7 12 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
1store Index
3i3 < 5is true
![Page 19: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/19.jpg)
7 12 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
1store Index
3i9 <= 11is true
![Page 20: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/20.jpg)
7 12 14 9 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
1store Index
3i
Swap
![Page 21: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/21.jpg)
7 9 14 12 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
1store Index
3i
Swap
![Page 22: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/22.jpg)
7 9 14 12 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
2store Index
3i
![Page 23: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/23.jpg)
7 9 14 12 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
2store Index
4i
![Page 24: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/24.jpg)
7 9 14 12 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
2store Index
4i4 < 5is true
![Page 25: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/25.jpg)
7 9 14 12 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
2store Index
4i10 <= 11
is true
![Page 26: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/26.jpg)
7 9 14 12 10 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
2store Index
4i
Swap
![Page 27: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/27.jpg)
7 9 10 12 14 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
2store Index
4i
Swap
![Page 28: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/28.jpg)
7 9 10 12 14 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
3store Index
4i
![Page 29: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/29.jpg)
7 9 10 12 14 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
3store Index
5i
![Page 30: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/30.jpg)
7 9 10 12 14 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
3store Index
5i
4 < 5is false
![Page 31: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/31.jpg)
7 9 10 12 14 11
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
3store Index
5i
Swap
![Page 32: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/32.jpg)
7 9 10 11 14 12
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
3store Index
5i
Swap
![Page 33: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/33.jpg)
7 9 10 11 14 12
begin last
int storeIndex = begin;for (int i = begin; i < last; i++) { if (array[i] <= array[last]) { Swap(array, i, storeIndex); storeIndex = storeIndex + 1; }}Swap(array, storeIndex, last);return storeIndex;
3store Index
5i
![Page 34: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/34.jpg)
Quicksort algorithm
Now we use Partition in the context of Quicksort
![Page 35: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/35.jpg)
9 7 5 11 12 2 14 3 10 6
int pivotIndex = 0;if (begin < last) { pivotIndex = Partition(array, begin, last); QuickSort(array, begin, pivotIndex - 1); QuickSort(array, pivotIndex + 1, last); }else { return;}
pivot Index
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
![Page 36: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/36.jpg)
9 7 5 11 12 2 14 3 10 6
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
0pivot Index
![Page 37: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/37.jpg)
9 7 5 11 12 2 14 3 10 6
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
0pivot Index
0 < 9is true
![Page 38: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/38.jpg)
9 7 5 11 12 2 14 3 10 6
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
0pivot Index
Partition0..9
![Page 39: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/39.jpg)
5 2 3 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
3pivot Index
these are <= 6 these are > 6
![Page 40: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/40.jpg)
5 2 3 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
3pivot Index
Call Stack #0
![Page 41: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/41.jpg)
5 2 3 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
pivot Index
Call Stack #0
Call Stack #1
![Page 42: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/42.jpg)
5 2 3 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
0pivot Index
![Page 43: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/43.jpg)
5 2 3 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
0pivot Index
0 < 2is true
![Page 44: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/44.jpg)
5 2 3 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
0pivot Index
Partition0..2
![Page 45: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/45.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
1pivot Index
![Page 46: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/46.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
1pivot Index
Call Stack #0
Call Stack #1
![Page 47: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/47.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
Call Stack #0
Call Stack #1
pivot Index
Call Stack #2
![Page 48: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/48.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
Call Stack #0
Call Stack #1
0pivot Index
Call Stack #2
![Page 49: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/49.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
Call Stack #0
Call Stack #1
0pivot Index
Call Stack #20 < 0
is false
![Page 50: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/50.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
Call Stack #0
Call Stack #1
0pivot Index
Call Stack #2
![Page 51: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/51.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
1pivot Index
Call Stack #0
Call Stack #1
![Page 52: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/52.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
Call Stack #0
Call Stack #1
pivot Index
Call Stack #2
![Page 53: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/53.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
Call Stack #0
Call Stack #1
0pivot Index
Call Stack #2
![Page 54: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/54.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
Call Stack #0
Call Stack #1
0pivot Index
Call Stack #20 < 0is false
![Page 55: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/55.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
Call Stack #0
Call Stack #1
0pivot Index
Call Stack #2
![Page 56: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/56.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
1pivot Index
Call Stack #0
Call Stack #1
return (at the end of the function. Implicit ‘return’ statement
![Page 57: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/57.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
3pivot Index
Call Stack #0
We are done with these elements!
![Page 58: Quicksort: illustrated step-by-step walk through](https://reader033.vdocument.in/reader033/viewer/2022052523/55619f9bd8b42ad9538b493c/html5/thumbnails/58.jpg)
2 3 5 6 12 7 14 9 10 11
int pivotIndex = 0;if (start < end) { pivotIndex = Partition(array, start, end); QuickSort(array, start, pivotIndex - 1); QuickSort(array, pivotIndex + 1, end); }else { return;}
pivot Index
Call Stack #0
Call Stack #1
Walkthrough ends here.The right hand side is also sorted as it recursively calls Quicksort.