1
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
A B X W P P V P D P C Y Z P
partitioned
partition element unpartitioned
p q
2
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
A B X W P P V P D P C Y Z P
p q
3
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
A B X W P P V P D P C Y Z P
p q
4
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
A B X W P P V P D P C Y Z P
p q
swap me
5
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
A B X W P P V P D P C Y Z P
p q
swap me
6
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
A B X W P P V P D P C Y Z P
p q
swap me
7
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
A B X W P P V P D P C Y Z P
p q
swap me swap me
8
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
A B C W P P V P D P X Y Z P
p q
9
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
A B C W P P V P D P X Y Z P
p q
swap me
10
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
A B C W P P V P D P X Y Z P
p q
swap me swap me
11
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
A B C P P P V P D W X Y Z P
p q
swap left
12
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P B C A P P V P D W X Y Z P
p q
13
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P B C A P P V P D W X Y Z P
p q
swap me
14
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P B C A P P V P D W X Y Z P
p q
swap me swap me
15
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P B C A D P V P P W X Y Z P
p q
swap right
16
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P B C A D P V P Z W X Y P P
p q
17
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P B C A D P V P Z W X Y P P
p q
swap me
18
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P B C A D P V P Z W X Y P P
p q
swap me swap me
19
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P B C A D P V P Z W X Y P P
p q
swap left
20
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P P C A D B V P Z W X Y P P
q
swap right
p
21
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P P C A D B V Y Z W X P P P
p q
22
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P P C A D B V Y Z W X P P P
p q
swap me
23
3-Way Partitioning
3-way partitioning. Choose partitioning element. Scan from left element. Scan from right for element. Exchange. Move to left or right end if equal. Repeat until pointers cross.
P P C A D B V Y Z W X P P P
p q
pointers cross
24
3-Way Partitioning
3-way partitioning. Swap elements on left with elements in middle. Swap elements on right with elements in middle.
P P C A D B Y Z W X P P P
p q
swap meswap me
V
25
3-Way Partitioning
3-way partitioning. Swap elements on left with elements in middle. Swap elements on right with elements in middle.
B P C A D P Y Z W X P P P
p q
swap meswap me
V
26
3-Way Partitioning
3-way partitioning. Swap elements on left with elements in middle. Swap elements on right with elements in middle.
B D C A P P Y Z W X P P P
p q
V
27
3-Way Partitioning
3-way partitioning. Swap elements on left with elements in middle. Swap elements on right with elements in middle.
B D C A P P Y Z W X P P P
p q
swap me swap me
V
28
3-Way Partitioning
3-way partitioning. Swap elements on left with elements in middle. Swap elements on right with elements in middle.
B D C A P P P Y Z W X P P V
p q
swap me swap me
29
3-Way Partitioning
3-way partitioning. Swap elements on left with elements in middle. Swap elements on right with elements in middle.
B D C A P P P P Z W X P Y V
p q
swap me swap me
30
3-Way Partitioning
3-way partitioning. Swap elements on left with elements in middle. Swap elements on right with elements in middle.
B D C A P P P P P W X Z Y V
p q
3-way partitioned!
Top Related