1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left element. n...

30
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

Transcript of 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left element. n...

Page 1: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 2: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 3: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 4: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 5: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 6: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 7: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 8: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 9: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 10: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 11: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 12: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 13: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 14: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 15: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 16: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 17: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 18: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 19: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 20: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 21: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 22: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 23: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 24: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 25: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 26: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 27: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 28: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 29: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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

Page 30: 1 3-Way Partitioning 3-way partitioning. n Choose partitioning element. n Scan from left  element. n Scan from right for  element. n Exchange. n Move.

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!