• Nenhum resultado encontrado

2.3 P D Algorithms

N/A
N/A
Protected

Academic year: 2022

Share "2.3 P D Algorithms"

Copied!
87
0
0

Texto

(1)

ROBERT SEDGEWICK | KEVIN WAYNE

F O U R T H E D I T I O N

Algorithms

http://algs4.cs.princeton.edu

Algorithms

ROBERT SEDGEWICK | KEVIN WAYNE

2.3 P ARTITIONING D EMOS

Sedgewick 2-way partitioning

Dijkstra 3-way partitioning

Bentley-McIlroy 3-way partitioning

dual-pivot partitioning

(2)

http://algs4.cs.princeton.edu ROBERT SEDGEWICK | KEVIN WAYNE

Algorithms

2.3 P ARTITIONING D EMOS

Sedgewick 2-way partitioning

Dijkstra 3-way partitioning

Bentley-McIlroy 3-way partitioning

dual-pivot partitioning

(3)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K R A T E L E P U I M Q C X O S

i j

stop i scan because a[i] >= a[lo]

(4)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K R A T E L E P U I M Q C X O S

i j

(5)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K R A T E L E P U I M Q C X O S

i j

(6)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K R A T E L E P U I M Q C X O S

i j

stop j scan and exchange a[i] with a[j]

(7)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A T E L E P U I M Q R X O S

i j

(8)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A T E L E P U I M Q R X O S

i j

(9)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A T E L E P U I M Q R X O S

i j

stop i scan because a[i] >= a[lo]

(10)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A T E L E P U I M Q R X O S

i j

(11)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A T E L E P U I M Q R X O S

i j

(12)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A T E L E P U I M Q R X O S

i j

stop j scan and exchange a[i] with a[j]

(13)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A I E L E P U T M Q R X O S

i j

(14)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A I E L E P U T M Q R X O S

i j

(15)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A I E L E P U T M Q R X O S

i j

stop i scan because a[i] >= a[lo]

(16)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A I E L E P U T M Q R X O S

i j

(17)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A I E L E P U T M Q R X O S

i j

(18)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A I E L E P U T M Q R X O S

i j

stop j scan and exchange a[i] with a[j]

(19)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A I E E L P U T M Q R X O S

i j

(20)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A I E E L P U T M Q R X O S

i j

stop i scan because a[i] >= a[lo]

(21)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

lo

K C A I E E L P U T M Q R X O S

i j

stop j scan because a[j] <= a[lo]

(22)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

When pointers cross.

Exchange a[lo] with a[j].

lo

K C A I E E L P U T M Q R X O S

i j

pointers cross: exchange a[lo] with a[j]

(23)

Quicksort partitioning demo

Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

When pointers cross.

Exchange a[lo] with a[j].

lo

E C A I E K L P U T M Q R X O S

hi j

partitioned!

(24)

http://algs4.cs.princeton.edu ROBERT SEDGEWICK | KEVIN WAYNE

Algorithms

2.3 P ARTITIONING D EMOS

Sedgewick 2-way partitioning

Dijkstra 3-way partitioning

Bentley-McIlroy 3-way partitioning

dual-pivot partitioning

(25)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

lo

P A B X W P P V P D P C Y Z

hi

lt i gt

(26)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

P A B X W P P V P D P C Y Z

lt i gt

unknown equal

(27)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A P B X W P P V P D P C Y Z

lt i gt

unknown less equal

(28)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B P X W P P V P D P C Y Z

lt i gt

unknown less

equal

(29)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B P Z W P P V P D P C Y X

lt i gt

greater unknown

less

equal

(30)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B P Y W P P V P D P C Z X

lt i gt

greater unknown

less

equal

(31)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B P C W P P V P D P Y Z X

lt i gt

less unknown greater

equal

(32)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B C P W P P V P D P Y Z X

lt i gt

less unknown greater

equal

(33)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B C P P P P V P D W Y Z X

lt i gt

less unknown greater

equal

(34)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B C P P P P V P D W Y Z X

lt i gt

less equal unknown greater

(35)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B C P P P P V P D W Y Z X

lt i gt

less equal unknown greater

(36)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B C P P P P V P D W Y Z X

lt i gt

less equal unknown greater

(37)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B C P P P P D P V W Y Z X

lt i gt

less equal greater

unknown

(38)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B C D P P P P P V W Y Z X

lt i gt

less equal greater

unknown

(39)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

A B C D P P P P P V W Y Z X

lt gt i

equal

less greater

(40)

Let v be partitioning item a[lo].

Scan i from left to right.

(a[i] < v): exchange a[lt] with a[i]; increment both lt and i(a[i] > v): exchange a[gt] with a[i]; decrement gt

(a[i] == v): increment i

Dijkstra 3-way partitioning demo

lo

A B C D P P P P P V W Y Z X

hi

lt gt

equal

less greater

(41)

http://algs4.cs.princeton.edu ROBERT SEDGEWICK | KEVIN WAYNE

Algorithms

2.3 P ARTITIONING D EMOS

Sedgewick 2-way partitioning

Dijkstra 3-way partitioning

Bentley-McIlroy 3-way partitioning

dual-pivot partitioning

(42)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P A B X W P P V P D P C Y Z

i j

p q

(43)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P A B X W P P V P D P C Y Z

i j

p q

(44)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P A B X W P P V P D P C Y Z

i j

p q

(45)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P A B X W P P V P D P C Y Z

i j

p q

hi

(46)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P A B X W P P V P D P C Y Z

i j

p q

hi

exchange a[i] with a[j]

(47)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P A B C W P P V P D P X Y Z

i j

p q

hi

(48)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P A B C W P P V P D P X Y Z

i j

p q

hi

(49)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P A B C W P P V P D P X Y Z

i j

p q

hi

exchange a[i] with a[j]

(50)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P A B C P P P V P D W X Y Z

i j

p q

hi

exchange a[i] with a[p] and increment p

(51)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P B C A P P V P D W X Y Z

i j

p q

hi

(52)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P B C A P P V P D W X Y Z

i j

p q

hi

(53)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P B C A P P V P D W X Y Z

i j

p q

hi

exchange a[i] with a[j]

(54)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P B C A D P V P P W X Y Z

i j

p q

hi

exchange a[j] with a[q] and decrement q

(55)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P B C A D P V P Z W X Y P

i j

p q

hi

(56)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P B C A D P V P Z W X Y P

i j

p q

hi

(57)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P B C A D P V P Z W X Y P

i j

p q

hi

exchange a[i] with a[j]

(58)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P B C A D P V P Z W X Y P

i j

p q

hi

exchange a[i] with a[p] and increment p

(59)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P P C A D B V P Z W X Y P

i j

p q

hi

exchange a[j] with a[q] and decrement q

(60)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P P C A D B V Y Z W X P P

i j

p q

hi

(61)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P P C A D B V Y Z W X P P

i j

p q

hi

(62)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P P C A D B V Y Z W X P P

i j

p q

hi

(63)

Bentley-McIlroy 3-way partitioning demo

Phase I. Repeat until i and j pointers cross.

Scan i from left to right so long as (a[i] < a[lo]).

Scan j from right to left so long as (a[j] > a[lo]).

Exchange a[i] with a[j].

If (a[i] == a[lo]), exchange a[i] with a[p] and increment p.

If (a[j] == a[lo]), exchange a[j] with a[q] and decrement q.

lo

P P P C A D B V Y Z W X P P

p q

hi i

j

pointers cross

(64)

Bentley-McIlroy 3-way partitioning demo

Phase II. Swap equal keys to the center.

Scan j and p from right to left and exchange a[j] with a[p].

Scan i and q from left to right and exchange a[i] with a[q].

lo

P P P C A D B V Y Z W X P P

i j

p q

hi

exchange a[j] with a[p]

(65)

Bentley-McIlroy 3-way partitioning demo

Phase II. Swap equal keys to the center.

Scan j and p from right to left and exchange a[j] with a[p].

Scan i and q from left to right and exchange a[i] with a[q].

lo

P P B C A D P V Y Z W X P P

i j

p q

hi

exchange a[j] with a[p]

(66)

Bentley-McIlroy 3-way partitioning demo

Phase II. Swap equal keys to the center.

Scan j and p from right to left and exchange a[j] with a[p].

Scan i and q from left to right and exchange a[i] with a[q].

lo

P D B C A P P V Y Z W X P P

i j

p q

hi

exchange a[j] with a[p]

(67)

Bentley-McIlroy 3-way partitioning demo

Phase II. Swap equal keys to the center.

Scan j and p from right to left and exchange a[j] with a[p].

Scan i and q from left to right and exchange a[i] with a[q].

lo

A D B C P P P V Y Z W X P P

i j

q

hi

exchange a[i] with a[q]

(68)

Bentley-McIlroy 3-way partitioning demo

Phase II. Swap equal keys to the center.

Scan j and p from right to left and exchange a[j] with a[p].

Scan i and q from left to right and exchange a[i] with a[q].

lo

A D B C P P P P Y Z W X V P

i j

q

hi

exchange a[i] with a[q]

(69)

Bentley-McIlroy 3-way partitioning demo

Phase II. Swap equal keys to the center.

Scan j and p from right to left and exchange a[j] with a[p].

Scan i and q from left to right and exchange a[i] with a[q].

lo

A D B C P P P P P Z W X V Y

i

j hi

3-way partitioned

Referências

Documentos relacionados

RESUMO: Este trabalho teve como cunho pedagógico mostrar para os alunos do 3º Ensino Médio da Escola Estadual Brandão de Amorim, no ano de 2015, a questão da história

(Valor: 0,8 ponto) Uma agência de viagens oferece aos seus primeiros clientes, na primeira semana do ano, três pacotes promocionais: Básico, Padrão e Luxo. No regulamento da

No estudo que ora apresentamos, em torno de Me llamo Rigoberta Menchú y así me nació la conciencia (1985), narrativa de cunho testemunhal, servir-nos-emos de alguns

Este capítulo trata da modelagem utilizada para analisar e projetar sensores baseados em SMF com trecho afunilado. Será descrita a modelagem utilizada para esses tipos de

a) dois sábados e dois dias úteis no período compreendido entre 1º de março de 2016 e 28 de fevereiro de 2017. As duas assembleias realizadas durante os dias úteis deverão ocorrer

Quando nos referimos a catalogação de partes de plantas a serem utilizadas como medicamento, observamos as especificidades de cada espécie. E neste uso, alguns aspectos

A situação de acolhimento institucional é vista em duas facetas distintas, de um lado ela é uma medida protetiva e necessária em casos onde a família não pode garantir

Para nível diário incluiu intercepto e 20 diferenças defasadas.. Para diferença diária incluiu 19