300 likes | 634 Views
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. partition element.
E N D
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 partition element unpartitioned partitioned
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-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 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 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 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 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-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 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 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 left 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
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 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 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 right 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
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 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 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 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 right 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 p q
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 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
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
swap me swap me 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 V Y Z W X P P P p q
swap me swap me 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 V Y Z W X P P P p q
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 V Y Z W X P P P p q
swap me swap me 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 V Y Z W X P P P p q
swap me swap me 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 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
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!