Professional Documents
Culture Documents
Practice Exercise 2 - Nalugon
Practice Exercise 2 - Nalugon
VALUES 16 23 14 28 13 11 21 26
INDEX 0 1 2 3 4 5 6 7
0+7 7
Median of left: 16 Median of right: 26 Median of the center: 2
= 2
= 3.5 = 4
[ 13, 26, 4] To be swapped to [ 13, 16, 26] So, 16 is the pivot element.
26 23 14 28 13 11 21 16
Pivot
26 23 14 28 13 11 21 16
i j pivot
Compare :
26 >= 16 = True
13 <= 16 = True
11 23 14 28 13 26 21 16
i j pivot
Compare :
23 >= 16 = True
13 <= 16 = True
11 13 14 28 23 26 21 16
i j pivot
Compare:
14 >= 16 = True
23 <= 16 = False
11 13 14 28 23 26 21 16
i j
Compare:
11 13 14 16 23 26 21 28
i j
Compare:
28 >= 16 = True
16 <= 16 = True
11 13 14 16 21 26 23 28
pivot i j
Compare:
21 >= 16 = True
23 <= 16 = False
11 13 14 16 21 26 23 28
pivot i j
Compare:
26 >= 16 = True
23 <= 16 = False
11 13 14 16 21 23 26 28
pivot i j
B.
VALUES 2 17 10 5 1 10 7
INDEX 0 1 2 3 4 5 6
0+6 6
Median of left: 2 Median of right: 7 Median of the center: 2
= 2
=3
2 17 10 7 1 10 5
i j pivot
Compare:
2 >= 5 = False
10 <= 5 = False
2 17 10 7 1 10 5
i j Pivot
Compare:
17 >= 5 = True
1 <= 5 = True
2 1 10 7 17 10 5
j i Pivot
Compare:
10 >= 5 = True
7 <= 5 = False
2 1 10 7 17 10 5
j i
2 1 5 7 17 10 10
j i
2 1 5 7 17 10 10
j i
2 >= 1 = True
2 1 5 7 17 10 10
I j
17 >= 10 = True
2 1 5 7 10 10 17
j i