|
|
partition(A,s,e) = partition array elements A[s] .. A[e-1] using pivot = A[s] Steps (recursions) performed by the Quick Sort Algorithm: Index --> 0 1 2 3 4 5 6 7 Input A[] = [5, 4, 1, 7, 2, 9, 3, 6] Pivot = 5 |
partition(A,s,e) = partition array elements A[s] .. A[e-1] using pivot = A[s] Steps (recursions) performed by the Quick Sort Algorithm: Index --> 0 1 2 3 4 5 6 7 Input A[] = [5, 4, 1, 7, 2, 9, 3, 6] Pivot = 5 <--------------------> partition(A,0,8): | V |
partition(A,s,e) = partition array elements A[s] .. A[e-1] using pivot = A[s] Steps (recursions) performed by the Quick Sort Algorithm: Index --> 0 1 2 3 4 5 6 7 Input A[] = [5, 4, 1, 7, 2, 9, 3, 6] Pivot = 5 <--------------------> partition(A,0,8): | V A[] = [2, 3, 4, 1, 5, 9, 7, 6] Pivot = 2 <--------> |
partition(A,s,e) = partition array elements A[s] .. A[e-1] using pivot = A[s] Steps (recursions) performed by the Quick Sort Algorithm: Index --> 0 1 2 3 4 5 6 7 Input A[] = [5, 4, 1, 7, 2, 9, 3, 6] Pivot = 5 <--------------------> partition(A,0,8): | V A[] = [2, 3, 4, 1, 5, 9, 7, 6] Pivot = 2 <--------> <-----> partition(A,0,4): | (still need sorting) V A[] = [1, 2, 4, 3, 5, 9, 7, 6] Pivot = 4 <--> 1 is "already" sorted |
partition(A,s,e) = partition array elements A[s] .. A[e-1] using pivot = A[s] Steps (recursions) performed by the Quick Sort Algorithm: Index --> 0 1 2 3 4 5 6 7 Input A[] = [5, 4, 1, 7, 2, 9, 3, 6] Pivot = 5 <--------------------> partition(A,0,8): | V A[] = [2, 3, 4, 1, 5, 9, 7, 6] Pivot = 2 <--------> partition(A,0,4): | V A[] = [1, 2, 4, 3, 5, 9, 7, 6] Pivot = 4 <--> partition(A,2,4): | V A[] = [1, 2, 3, 4, 5, 9, 7, 6] Pivot = 9 <-----> 3 is "already" sorted |
partition(A,s,e) = partition array elements A[s] .. A[e-1] using pivot = A[s] Steps (recursions) performed by the Quick Sort Algorithm: Index --> 0 1 2 3 4 5 6 7 Input A[] = [5, 4, 1, 7, 2, 9, 3, 6] Pivot = 5 <--------------------> partition(A,0,8): | V A[] = [2, 3, 4, 1, 5, 9, 7, 6] Pivot = 2 <--------> partition(A,0,4): | V A[] = [1, 2, 4, 3, 5, 9, 7, 6] Pivot = 4 <--> partition(A,2,4): | V A[] = [1, 2, 3, 4, 5, 9, 7, 6] Pivot = 9 <-----> partition(A,5,8): | V |
partition(A,s,e) = partition array elements A[s] .. A[e-1] using pivot = A[s] Steps (recursions) performed by the Quick Sort Algorithm: Index --> 0 1 2 3 4 5 6 7 Input A[] = [5, 4, 1, 7, 2, 9, 3, 6] Pivot = 5 <--------------------> partition(A,0,8): | V A[] = [2, 3, 4, 1, 5, 9, 7, 6] Pivot = 2 <--------> partition(A,0,4): | V A[] = [1, 2, 4, 3, 5, 9, 7, 6] Pivot = 4 <--> partition(A,2,4): | V A[] = [1, 2, 3, 4, 5, 9, 7, 6] Pivot = 9 <-----> partition(A,5,8): | V A[] = [1, 2, 3, 4, 5, 7, 6, 9] Pivot = 7 <--> |
partition(A,s,e) = partition array elements A[s] .. A[e-1] using pivot = A[s] Steps (recursions) performed by the Quick Sort Algorithm: Index --> 0 1 2 3 4 5 6 7 Input A[] = [5, 4, 1, 7, 2, 9, 3, 6] Pivot = 5 <--------------------> partition(A,0,8): | V A[] = [2, 3, 4, 1, 5, 9, 7, 6] Pivot = 2 <--------> partition(A,0,4): | V A[] = [1, 2, 4, 3, 5, 9, 7, 6] Pivot = 4 <--> partition(A,2,4): | V A[] = [1, 2, 3, 4, 5, 9, 7, 6] Pivot = 9 <-----> partition(A,5,8): | V A[] = [1, 2, 3, 4, 5, 7, 6, 9] Pivot = 7 <--> partition(A,5,7): | V A[] = [1, 2, 3, 4, 5, 6, 7, 9] Done |
|
|
|
|
We will study the partition(A, s, e) method in the next slide