3-Way Partitioning - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

3-Way Partitioning

Description:

Scan from left element. Scan from right for element. Exchange. ... – PowerPoint PPT presentation

Number of Views:65
Avg rating:3.0/5.0
Slides: 31
Provided by: kevin59
Category:
Tags: partitioning | scan | way

less

Transcript and Presenter's Notes

Title: 3-Way Partitioning


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
p
q
partition element
unpartitioned
partitioned
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
V
p
q
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
V
p
q
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
V
p
q
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
V
p
q
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
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
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!
Write a Comment
User Comments (0)
About PowerShow.com