I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle...

432
I. Course Intro and Sorting Networks Thomas Sauerwald Easter 2016

Transcript of I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle...

Page 1: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

I. Course Intro and Sorting NetworksThomas Sauerwald

Easter 2016

Page 2: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Outline

Outline of this Course

Some Highlights

Introduction to Sorting Networks

Batcher’s Sorting Network

Counting Networks

Load Balancing on Graphs

I. Course Intro and Sorting Networks Outline of this Course 2

Page 3: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

(Tentative) List of Topics

IA Algorithms IB Complexity Theory II Advanced Algorithms

I. Sorting Networks (Sorting, Counting, Load Balancing)

II. Matrix Multiplication

III. Linear Programming

IV. Approximation Algorithms: Covering ProblemsV. Approximation Algorithms via Exact AlgorithmsVI. Approximation Algorithms: Travelling Salesman ProblemVII. Approximation Algorithms: Randomisation and RoundingVIII. Approximation Algorithms: MAX-CUT Problem (if time permits)

closely follow CLRS3 and use the same numberring

however, slides will be self-contained (mostly)

I. Course Intro and Sorting Networks Outline of this Course 3

Page 4: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

(Tentative) List of Topics

IA Algorithms IB Complexity Theory II Advanced Algorithms

I. Sorting Networks (Sorting, Counting, Load Balancing)

II. Matrix Multiplication

III. Linear Programming

IV. Approximation Algorithms: Covering ProblemsV. Approximation Algorithms via Exact AlgorithmsVI. Approximation Algorithms: Travelling Salesman ProblemVII. Approximation Algorithms: Randomisation and RoundingVIII. Approximation Algorithms: MAX-CUT Problem (if time permits)

closely follow CLRS3 and use the same numberring

however, slides will be self-contained (mostly)

I. Course Intro and Sorting Networks Outline of this Course 3

Page 5: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

(Tentative) List of Topics

IA Algorithms IB Complexity Theory II Advanced Algorithms

I. Sorting Networks (Sorting, Counting, Load Balancing)

II. Matrix Multiplication

III. Linear Programming

IV. Approximation Algorithms: Covering ProblemsV. Approximation Algorithms via Exact AlgorithmsVI. Approximation Algorithms: Travelling Salesman ProblemVII. Approximation Algorithms: Randomisation and RoundingVIII. Approximation Algorithms: MAX-CUT Problem (if time permits)

closely follow CLRS3 and use the same numberring

however, slides will be self-contained (mostly)

I. Course Intro and Sorting Networks Outline of this Course 3

Page 6: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

(Tentative) List of Topics

IA Algorithms IB Complexity Theory II Advanced Algorithms

I. Sorting Networks (Sorting, Counting, Load Balancing)

II. Matrix Multiplication

III. Linear Programming

IV. Approximation Algorithms: Covering ProblemsV. Approximation Algorithms via Exact AlgorithmsVI. Approximation Algorithms: Travelling Salesman ProblemVII. Approximation Algorithms: Randomisation and RoundingVIII. Approximation Algorithms: MAX-CUT Problem (if time permits)

closely follow CLRS3 and use the same numberring

however, slides will be self-contained (mostly)

I. Course Intro and Sorting Networks Outline of this Course 3

Page 7: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Outline

Outline of this Course

Some Highlights

Introduction to Sorting Networks

Batcher’s Sorting Network

Counting Networks

Load Balancing on Graphs

I. Course Intro and Sorting Networks Some Highlights 4

Page 8: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Linear Programming and Simplex

x1

x2

x3

(0, 0, 0)

(9, 0, 0)

(8.25, 0, 1.5)(8, 4, 0)

(0, 12, 0)

(0, 0, 4.8)

0

27

27.7528

12

9.6

maximize 3x1 + x2 + 2x3subject to

x1 + x2 + 3x3 ≤ 302x1 + 2x2 + 5x3 ≤ 244x1 + x2 + 2x3 ≤ 36

x1, x2, x3 ≥ 0

I. Course Intro and Sorting Networks Some Highlights 5

Page 9: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Linear Programming and Simplex

x1

x2

x3

(0, 0, 0)

(9, 0, 0)

(8.25, 0, 1.5)(8, 4, 0)

(0, 12, 0)

(0, 0, 4.8)

0

27

27.7528

12

9.6

maximize 3x1 + x2 + 2x3subject to

x1 + x2 + 3x3 ≤ 302x1 + 2x2 + 5x3 ≤ 244x1 + x2 + 2x3 ≤ 36

x1, x2, x3 ≥ 0

I. Course Intro and Sorting Networks Some Highlights 5

Page 10: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Linear Programming and Simplex

x1

x2

x3

(0, 0, 0)

(9, 0, 0)

(8.25, 0, 1.5)(8, 4, 0)

(0, 12, 0)

(0, 0, 4.8)

0

27

27.7528

12

9.6

maximize 3x1 + x2 + 2x3subject to

x1 + x2 + 3x3 ≤ 302x1 + 2x2 + 5x3 ≤ 244x1 + x2 + 2x3 ≤ 36

x1, x2, x3 ≥ 0

I. Course Intro and Sorting Networks Some Highlights 5

Page 11: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Linear Programming and Simplex

x1

x2

x3

(0, 0, 0)

(9, 0, 0)

(8.25, 0, 1.5)(8, 4, 0)

(0, 12, 0)

(0, 0, 4.8)

0

27

27.7528

12

9.6

maximize 3x1 + x2 + 2x3subject to

x1 + x2 + 3x3 ≤ 302x1 + 2x2 + 5x3 ≤ 244x1 + x2 + 2x3 ≤ 36

x1, x2, x3 ≥ 0

I. Course Intro and Sorting Networks Some Highlights 5

Page 12: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Linear Programming and Simplex

x1

x2

x3

(0, 0, 0)

(9, 0, 0)

(8.25, 0, 1.5)(8, 4, 0)

(0, 12, 0)

(0, 0, 4.8)

0

27

27.7528

12

9.6

maximize 3x1 + x2 + 2x3subject to

x1 + x2 + 3x3 ≤ 302x1 + 2x2 + 5x3 ≤ 244x1 + x2 + 2x3 ≤ 36

x1, x2, x3 ≥ 0

I. Course Intro and Sorting Networks Some Highlights 5

Page 13: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

The Original Article (1954)

SOLUTION OF A LARGE-SCALE TRAVELING-SALESMAN PROBLEM*

G. DANTZIG, R. FULKERSON, AND S. JOHNSON The Rand Corporation, Santa Monica, California

(Received August 9, 1954)

It is shown that a certain tour of 49 cities, one in each of the 48 states and Washington, D. C., has the shortest road distance.

THE TRAVELING-SALESMAN PROBLEM might be described as follows: Find the shortest route (tour) for a salesman starting from a

given city, visiting each of a specified group of cities, and then returning to the original point of departure. More generally, given an n by n sym- metric matrix D= (d1i), where doi represents the 'distance' from I to J, arrange the points in a cyclic order in such a way that the sum of the d1j between consecutive points is minimal. Since there are only a finite number of possibilities (at most (n - 1)!) to consider, the problem is to devise a method of picking out the optimal arrangement which is reasonably efficient for fairly large values of n. Although algorithms have been devised for problems of similar nature, e.g., the optimal assignment problem,3"78 little is known about the traveling-salesman problem. We do not claim that this note alters the situation very much; what we shall do is outline a way of approaching the problem that sometimes, at least, en- ables one to find an optimal path and prove it so. In particular, it will be shown that a certain arrangement of 49 cities, one in each of the 48 states and Washington, D. C., is best, the djj used representing road distances as taken from an atlas.

* HISTORICAL NOTE: The origin of this problem is somewhat obscure. It appears to have been discussed informally among mathematicians at mathematics meetings for many years. Surprisingly little in the way of results has appeared in the mathematical literature.10 It may be that the minimal-distance tour problem was stimulated by the so-called Hamiltonian game' which is concerned with finding the number of different tours possible over a specified network. The latter problem is cited by some as the origin of group theory and has some connections with the famous Four-Color Conjecture.9 Merrill Flood (Columbia University) should be credited with stimulating interest in the traveling-salesman problem in many quar- ters. As early as 1937, he tried to obtain near optimal solutions in reference to routing of school buses. Both Flood and A. W. Tucker (Princeton University) re- call that they heard about the problem first in a seminar talk by Hassler Whitney at Princeton in 1934 (although Whitney, recently queried, does not seem to recall the problem). The relations between the traveling-salesman problem and the transportation problem of linear programming appear to have been first explored by M. Flood, J. Robinson, T. C. Koopmans, M. Beckmann, and later by I. Heller and H. Kuhn.4 5'6

393

I. Course Intro and Sorting Networks Some Highlights 6

Page 14: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Travelling Salesman Problem: The 42 (49) Cities

394 DANTZIG, FULKERSON, AND JOHNSON

In order to try the method on a large problem, the following set of 49 cities, one in each state and the District of Columbia was selected:

1. Manchester, N. HI. 18. Carson City, Nev. 34. Birmingham, Ala. 2. Montpelier, Vt. 19. Los Angeles, Calif. 35. Atlanta, Ga. 3. Detroit, Mich. 20. Phoenix, Ariz. 36. Jacksonville, Fla. 4. Cleveland, Ohio 21. Santa Fe, N. M. 37. Columbia, S. C. 5. Charleston, W. Va. 22. Denver, Colo. 38. Raleigh, N. C. 6. Louisville, Ky. 23. Cheyenne, Wyo. 39. Richmond, Va. 7. Indianapolis, Ind. 24. Omaha, Neb. 40. Washington, D. C. 8. Chicago, Ill. 25. Des Moines, Iowa 41. Boston, Mass. 9. Milwaukee, Wis. 26. Kansas City, Mo. 42. Portland, Me.

10. Minneapolis, Minn. 27. Topeka, Kans. A. BaltimoreA Md.

12. Bismark, N. D. 28. Oklahoma City, Okla. B. Wilmington, Del. 13. Helenar, MNt. 29. Dallas, Tex. C. Philadelphia, Penn. 14. Seattle, Wash. 30. Little Rock, Ark. D. Newark, N. J. 15. Portland, Ore. 31. Memphis, Tenn. E. New York, N. Y. 16. Boise, Idaho 32. Jackson, Miss. F. Hartford, Conn. 17. Salt Lake City, Utah 33. New Orleans, La. G. Providence, R. I.

The reason for picking this particular set was that most of the road distances between them were easy to get from an atlas. The triangular table of distances between these cities (Table I) is part of the original one prepared by Bernice Brown of The Rand Corporation. It gives dj= K7 (di; - 11) (IJ = 1, 2, * , 42), where dii is the road distance in miles between I and J. The d1i have been rounded to the nearest integer. Certainly such a linear transformation does not alter the ordering of the tour lengths, although, of course, rounding could cause a tour that was not optimal in terms of the original mileage to become optimal in terms of the adjusted units used in this paper.

We will show that the tour (see Fig. 16) through the cities 1, 2, * *, 42 in this order is minimal for this subset of 42 cities. Moreover, since in driving from city 40 (Washington, D. C.) to city 41 (Boston, Massachusetts) by the shortest road distance one goes through A, B, * * *, G, successively, it follows that the tour through 49 cities 1, 2, .*, 40, A, B, *., G, 41, 42 in that order is also optimal.

PRELIMINARY NOTIONS

Whenever the road from I to J (in that order) is traveled, the value XIJ I is entered into the IJ element of a matrix; otherwise xiJ 0 is entered. A (directed) tour through n cities can now be thought of as a permutation matrix of order n which represents an n-cycle (we assume

* This particular transformation was chosen to make the d1j of the original table less than 256 which would permit compact storage of the distance table in binary representation; however, no use was made of this.

I. Course Intro and Sorting Networks Some Highlights 7

Page 15: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Road Distances

\0) cO

0O

00 n

00 e

cn C

- I- tr\

o C

NC

cl

cn cn -t 00

rN

C4

f 0

00\,O

0 tn

0 \ '

CC

, C

-) n

n\ ,O

c 0

t Q

>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0

O.

0 q O

00 ol

o e

S~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~i c

Ct'I t n

+ + t-oo

0 N

0

0 >

n cn

0 t-

z >

? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C,

C,>

e ?-\,

roo +r" 0

e 0

? 0

? \o

0 c

o O

-

t" 00 ]00 C~

H

F ,,

E m

N

> +

> >

t +

+ ?

+?t +

O

4~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~t

t Q

' m

+mO

>

tw#)b

.-w9

C-4 C

, C

4 Q

o \1-

\0 0

00 ac s

(0 iC

it

3 i0

t 00

I- ,

t1 ?

t (~~~~~~~n Itm

-< . r -\o

,O C

o ~O rO

o e 4

? 6>t I

00 M

M

f-

4 r > 00

C6 O

He %4

00) Q

o

an ~

b 6

on 6

H

X

? O

H

ct

+ tn

a> a> 4

0

S~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cn r

Xbt

Xe\o \0

to 00

0 0 C

, O 0

On m

?i

? 00 0tC

I 0

0 0 00 .

00 ??o 00

L"O

tO

ci t es ) c i t'Thf?ci

.00' 000

cn st 0,

4i

~ ~4-~0) 00

ci C

) C

S) t~ 'tci\O

'-ci t0-~ ~, j.0

t 0- H

00

0C

i

cd -,o

o-o r-

coZ\~ 00

oo O

(7

0 ft+m

? s

SA?

c H

cn

ocall 0 0

0 W

C

S- o

tn o

cic~~-000000 00m

000-'-'M~

c 00c

Z t '.'

t0 t"-'t00

ci) 0

i 0

H

a -

tc t Z-000

ci 00

V-.

t O

0)' C

, 0

0 0

0"0o C

it N

', ''

kf ~~

)'t'ci0000 -~~~~~~~ci'C

00 0000

d I0~0

cic -p\

- 0

ci 0

0 O~~~~(~~f--~~

'-cic~~ 0',tci0',00 O

~~~~c-) ~~ t-0',tfl\,~~~~ ci00

0 C

X~~~~~~~~~~~~~~~~~~~~-

*0 C

' -

)+ mo v00

1c HF

tl C

A C

n C

,oo

t- o

_I

-o o

ci ~cif-~0

O

0 0

', -,

, 00

- t

r 0

o 0

C

C

c F4

i "

0 \O

'-ci00 ci

0N00\0

00 f--0000

-00X-=

~-A

tit- c

CA

"C

, 00

0N0c'c

ci 0

c c

i c00 roN

C

o\ r'

" 04

r r0

00 -\

"O

cm

C\

m

0 rb4

t- -t

r\. o

mO

O

CP\ 0

0 t3n C

n \ d

UN

CP\00 r-0

0 0

c 0

i 0

't '

0 N

,

' b0

""O

-- m

0 00

ci m

m00 0

't 'tci)00

080 ON

i00

fm cN

'

0 '0

'

0) ci

ci '-'~0

'-ci'~0 'tf--00 000000

ON

O

c \.O

ci

t- ',tr

~\C 0

wm

ci 'tci)'-ci00

00 f--i

c o

it N ci m

4 c

cO

n q- tn

W

0e ci'-

O~ci

0-?O ci

~i't"0 'ciO

NO

ci

c I-,0 O

N-

'-cic'o -,o

OC

) CO

C

)'c\ . tO

X

o0 0) Q

r0 F-

0 C

')'t t-4

4 0

0 f-

C=

f\ C

%

f 00

-*

c')t C

4 "

) 'cX

Io --\O

t -f

ON

0

ci c

c cn

t -

'tO-00

+

00 .)

- I

C, ) 0)

F- H

-00

0)0 O

N

ON

OC

= 0

-

\O

-CO

ciO

N rC

'

CA

o

't00 )o

n O

N O

rt

O

C' )\00

ci ' rcic

o 00- o"-

-

-0 00

000 '-

c ci

\i' C

) "0f--00

0 0

M

0 0

- O

N

CIA

O

0Ci-'

0 0

0- r0

00 C

0 ci C

00

0-ON

I- c

i '

- 0

-c c

0

ci i

- 00

0-0 c

0 'H

'tc C

n C

Y'o

-I '.

-0 00

Ot

) 0000

- C

A

11- -00

Ci ci

000 ?

W

0 C

c "

' -

- -

- O

- -00N

0

M'-

\o 0

c M

q0-~ 0N

cc-\,O

N'.0

"C ci

OO

N ci

\,O 00 \000

ci 't~~~ci00ciC

')C00c~~ic0

'-~ \O

Cic

CA

ic cn -,i,-4t

tj

t -

O

MO

O ',

O

O

V

- 0\,

C)

',) '.O

ON

NC

) 00

" C

) , --

-C

C'\00

0 ci

'I O

O

'4 .

Cl C

n 0 000

O

t 0

0M

- O

-???

r

f-o- 0

C,

-'t O

0 0

C0

' t --C

-) o

0 00

0\, - O

'ci00

OC

A

t 00

0 M

t

ci C

')'-ci f---

C''-

' t '3 t o ci o)0000

'-cit ' t't

0'-t c')'-+W

'c )

t ci

0 V

6 V

c

ci ci ~~~

~ 't'0 0-C

f- -'c

ci ('

''c )0

0'-- '-i-

-vi -l0'"

'CA

~ici c

0c 0 X

ci 0-

ci 0 't0"0

0-'-800c C"C

i 0

, 0

C')'t

', 00

C,)

cn i'c

tl '''

-i i'c

f cici

CA

ci I-

\- .-0

-N#-

CA

-,

c N

.t ''

C'.

iN-tc'c)

' o~~~~~~~~~~~~~~~~~~~~~~~C

H

7O

r- -1

r tn

3 \3 ,O

45

m

C4

CA

-n+<

t6> c n

'-f 0

O Ci4

\ - 'I-

i O

\cO

O

00

0)0 cn

')ci '-'-

i-I O

- O

N-C

f--"-,

'-) m

i ' 0

%,O

0O

'

tt-\ 00\ )O

c\

0 04

0) O

NC

f

ON

-\ C

> Y

C

f- O

ci'3 '

+ + +

)00 0 O

a -0

00 ooci

C",00

'-ci'-o C

-- ci

't'-ci f--f--

f-i '

i- 00

i cO

NcO

N

0 0-

0C

-

C'O

cim -c

-n --N

o 000

o 0 0w

'0000 1.

t-0 C

" ,'- r-

00 'T0

CO

N 00

O

sf-C-A

f-

' iti

c

Nm

m

M

) 'i s)

ooO

OO

y

QtN

130dt 000 C

~, O

i

Z o

o M

c \O

8-Q

-) C

\

S~~~~~~~diF~~~~~~~" r*tO

"_ G

e .-

Vd iU4("

N6~h

Neez

F#0 )

-mm

etm

mbo

mm

I. Course Intro and Sorting Networks Some Highlights 8

Page 16: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

The (Unique) Optimal Tour (699 Units ≈ 12,345 miles)

C)

Ul)~~~~~

I X

4

0

CC

A

0~~~~~~~~~~0

* |

~~~A

./H

'-

fCs

E 4*

400 ~

~ ~

0

_~~~~~~~~~ V

40M

<

I. Course Intro and Sorting Networks Some Highlights 9

Page 17: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Outline

Outline of this Course

Some Highlights

Introduction to Sorting Networks

Batcher’s Sorting Network

Counting Networks

Load Balancing on Graphs

I. Course Intro and Sorting Networks Introduction to Sorting Networks 10

Page 18: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Overview: Sorting Networks

we already know several (comparison-based) sorting algorithms:Insertion sort, Bubble sort, Merge sort, Quick sort, Heap sort

execute one operation at a time

can handle arbitrarily large inputs

sequence of comparisons is not set in advance

(Serial) Sorting Algorithms

only perform comparisons

can only handle inputs of a fixed size

sequence of comparisons is set in advance

Comparisons can be performed in parallel

Sorting Networks

Allows to sort n numbersin sublinear time!

Simple concept, but surprisingly deep and complex theory!

I. Course Intro and Sorting Networks Introduction to Sorting Networks 11

Page 19: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Overview: Sorting Networks

we already know several (comparison-based) sorting algorithms:Insertion sort, Bubble sort, Merge sort, Quick sort, Heap sort

execute one operation at a time

can handle arbitrarily large inputs

sequence of comparisons is not set in advance

(Serial) Sorting Algorithms

only perform comparisons

can only handle inputs of a fixed size

sequence of comparisons is set in advance

Comparisons can be performed in parallel

Sorting Networks

Allows to sort n numbersin sublinear time!

Simple concept, but surprisingly deep and complex theory!

I. Course Intro and Sorting Networks Introduction to Sorting Networks 11

Page 20: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Overview: Sorting Networks

we already know several (comparison-based) sorting algorithms:Insertion sort, Bubble sort, Merge sort, Quick sort, Heap sort

execute one operation at a time

can handle arbitrarily large inputs

sequence of comparisons is not set in advance

(Serial) Sorting Algorithms

only perform comparisons

can only handle inputs of a fixed size

sequence of comparisons is set in advance

Comparisons can be performed in parallel

Sorting Networks

Allows to sort n numbersin sublinear time!

Simple concept, but surprisingly deep and complex theory!

I. Course Intro and Sorting Networks Introduction to Sorting Networks 11

Page 21: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Overview: Sorting Networks

we already know several (comparison-based) sorting algorithms:Insertion sort, Bubble sort, Merge sort, Quick sort, Heap sort

execute one operation at a time

can handle arbitrarily large inputs

sequence of comparisons is not set in advance

(Serial) Sorting Algorithms

only perform comparisons

can only handle inputs of a fixed size

sequence of comparisons is set in advance

Comparisons can be performed in parallel

Sorting Networks

Allows to sort n numbersin sublinear time!

Simple concept, but surprisingly deep and complex theory!

I. Course Intro and Sorting Networks Introduction to Sorting Networks 11

Page 22: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Comparison Networks

A comparison network consists solely of wires and comparators:

comparator is a device with, on given two inputs, x and y , returns twooutputs x ′ = min(x , y) and y ′ = max(x , y)wire connect output of one comparator to the input of anotherspecial wires: n input wires a1, a2, . . . , an and n output wires b1, b2, . . . , bn

Comparison Network

27.1 Comparison networks 705

comparator

(a) (b)

7

3

3

7 xx

yy

x ! = min(x, y)x ! = min(x, y)

y! = max(x, y)y! = max(x, y)

Figure 27.1 (a) A comparator with inputs x and y and outputs x ! and y!. (b) The same comparator,drawn as a single vertical line. Inputs x = 7, y = 3 and outputs x ! = 3, y! = 7 are shown.

A comparison network is composed solely of wires and comparators. A compara-tor, shown in Figure 27.1(a), is a device with two inputs, x and y, and two outputs,x ! and y!, that performs the following function:

x ! = min(x, y) ,

y! = max(x, y) .

Because the pictorial representation of a comparator in Figure 27.1(a) is toobulky for our purposes, we shall adopt the convention of drawing comparators assingle vertical lines, as shown in Figure 27.1(b). Inputs appear on the left andoutputs on the right, with the smaller input value appearing on the top output andthe larger input value appearing on the bottom output. We can thus think of acomparator as sorting its two inputs.

We shall assume that each comparator operates in O(1) time. In other words,we assume that the time between the appearance of the input values x and y andthe production of the output values x ! and y! is a constant.

A wire transmits a value from place to place. Wires can connect the outputof one comparator to the input of another, but otherwise they are either networkinput wires or network output wires. Throughout this chapter, we shall assumethat a comparison network contains n input wires a1, a2, . . . , an , through whichthe values to be sorted enter the network, and n output wires b1, b2, . . . , bn , whichproduce the results computed by the network. Also, we shall speak of the inputsequence "a1, a2, . . . , an# and the output sequence "b1, b2, . . . , bn#, referring tothe values on the input and output wires. That is, we use the same name for both awire and the value it carries. Our intention will always be clear from the context.

Figure 27.2 shows a comparison network, which is a set of comparators inter-connected by wires. We draw a comparison network on n inputs as a collectionof n horizontal lines with comparators stretched vertically. Note that a line doesnot represent a single wire, but rather a sequence of distinct wires connecting vari-ous comparators. The top line in Figure 27.2, for example, represents three wires:input wire a1, which connects to an input of comparator A; a wire connecting thetop output of comparator A to an input of comparator C; and output wire b1, whichcomes from the top output of comparator C . Each comparator input is connected

operates in O(1)

Convention: use the same name for both a wire and its value.

A sorting network is a comparison network whichworks correctly (that is, it sorts every input)

I. Course Intro and Sorting Networks Introduction to Sorting Networks 12

Page 23: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Comparison Networks

A comparison network consists solely of wires and comparators:comparator is a device with, on given two inputs, x and y , returns twooutputs x ′ = min(x , y) and y ′ = max(x , y)

wire connect output of one comparator to the input of anotherspecial wires: n input wires a1, a2, . . . , an and n output wires b1, b2, . . . , bn

Comparison Network

27.1 Comparison networks 705

comparator

(a) (b)

7

3

3

7 xx

yy

x ! = min(x, y)x ! = min(x, y)

y! = max(x, y)y! = max(x, y)

Figure 27.1 (a) A comparator with inputs x and y and outputs x ! and y!. (b) The same comparator,drawn as a single vertical line. Inputs x = 7, y = 3 and outputs x ! = 3, y! = 7 are shown.

A comparison network is composed solely of wires and comparators. A compara-tor, shown in Figure 27.1(a), is a device with two inputs, x and y, and two outputs,x ! and y!, that performs the following function:

x ! = min(x, y) ,

y! = max(x, y) .

Because the pictorial representation of a comparator in Figure 27.1(a) is toobulky for our purposes, we shall adopt the convention of drawing comparators assingle vertical lines, as shown in Figure 27.1(b). Inputs appear on the left andoutputs on the right, with the smaller input value appearing on the top output andthe larger input value appearing on the bottom output. We can thus think of acomparator as sorting its two inputs.

We shall assume that each comparator operates in O(1) time. In other words,we assume that the time between the appearance of the input values x and y andthe production of the output values x ! and y! is a constant.

A wire transmits a value from place to place. Wires can connect the outputof one comparator to the input of another, but otherwise they are either networkinput wires or network output wires. Throughout this chapter, we shall assumethat a comparison network contains n input wires a1, a2, . . . , an , through whichthe values to be sorted enter the network, and n output wires b1, b2, . . . , bn , whichproduce the results computed by the network. Also, we shall speak of the inputsequence "a1, a2, . . . , an# and the output sequence "b1, b2, . . . , bn#, referring tothe values on the input and output wires. That is, we use the same name for both awire and the value it carries. Our intention will always be clear from the context.

Figure 27.2 shows a comparison network, which is a set of comparators inter-connected by wires. We draw a comparison network on n inputs as a collectionof n horizontal lines with comparators stretched vertically. Note that a line doesnot represent a single wire, but rather a sequence of distinct wires connecting vari-ous comparators. The top line in Figure 27.2, for example, represents three wires:input wire a1, which connects to an input of comparator A; a wire connecting thetop output of comparator A to an input of comparator C; and output wire b1, whichcomes from the top output of comparator C . Each comparator input is connected

operates in O(1)

Convention: use the same name for both a wire and its value.

A sorting network is a comparison network whichworks correctly (that is, it sorts every input)

I. Course Intro and Sorting Networks Introduction to Sorting Networks 12

Page 24: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Comparison Networks

A comparison network consists solely of wires and comparators:comparator is a device with, on given two inputs, x and y , returns twooutputs x ′ = min(x , y) and y ′ = max(x , y)

wire connect output of one comparator to the input of anotherspecial wires: n input wires a1, a2, . . . , an and n output wires b1, b2, . . . , bn

Comparison Network

27.1 Comparison networks 705

comparator

(a) (b)

7

3

3

7 xx

yy

x ! = min(x, y)x ! = min(x, y)

y! = max(x, y)y! = max(x, y)

Figure 27.1 (a) A comparator with inputs x and y and outputs x ! and y!. (b) The same comparator,drawn as a single vertical line. Inputs x = 7, y = 3 and outputs x ! = 3, y! = 7 are shown.

A comparison network is composed solely of wires and comparators. A compara-tor, shown in Figure 27.1(a), is a device with two inputs, x and y, and two outputs,x ! and y!, that performs the following function:

x ! = min(x, y) ,

y! = max(x, y) .

Because the pictorial representation of a comparator in Figure 27.1(a) is toobulky for our purposes, we shall adopt the convention of drawing comparators assingle vertical lines, as shown in Figure 27.1(b). Inputs appear on the left andoutputs on the right, with the smaller input value appearing on the top output andthe larger input value appearing on the bottom output. We can thus think of acomparator as sorting its two inputs.

We shall assume that each comparator operates in O(1) time. In other words,we assume that the time between the appearance of the input values x and y andthe production of the output values x ! and y! is a constant.

A wire transmits a value from place to place. Wires can connect the outputof one comparator to the input of another, but otherwise they are either networkinput wires or network output wires. Throughout this chapter, we shall assumethat a comparison network contains n input wires a1, a2, . . . , an , through whichthe values to be sorted enter the network, and n output wires b1, b2, . . . , bn , whichproduce the results computed by the network. Also, we shall speak of the inputsequence "a1, a2, . . . , an# and the output sequence "b1, b2, . . . , bn#, referring tothe values on the input and output wires. That is, we use the same name for both awire and the value it carries. Our intention will always be clear from the context.

Figure 27.2 shows a comparison network, which is a set of comparators inter-connected by wires. We draw a comparison network on n inputs as a collectionof n horizontal lines with comparators stretched vertically. Note that a line doesnot represent a single wire, but rather a sequence of distinct wires connecting vari-ous comparators. The top line in Figure 27.2, for example, represents three wires:input wire a1, which connects to an input of comparator A; a wire connecting thetop output of comparator A to an input of comparator C; and output wire b1, whichcomes from the top output of comparator C . Each comparator input is connected

operates in O(1)

Convention: use the same name for both a wire and its value.

A sorting network is a comparison network whichworks correctly (that is, it sorts every input)

I. Course Intro and Sorting Networks Introduction to Sorting Networks 12

Page 25: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Comparison Networks

A comparison network consists solely of wires and comparators:comparator is a device with, on given two inputs, x and y , returns twooutputs x ′ = min(x , y) and y ′ = max(x , y)wire connect output of one comparator to the input of another

special wires: n input wires a1, a2, . . . , an and n output wires b1, b2, . . . , bn

Comparison Network

27.1 Comparison networks 705

comparator

(a) (b)

7

3

3

7 xx

yy

x ! = min(x, y)x ! = min(x, y)

y! = max(x, y)y! = max(x, y)

Figure 27.1 (a) A comparator with inputs x and y and outputs x ! and y!. (b) The same comparator,drawn as a single vertical line. Inputs x = 7, y = 3 and outputs x ! = 3, y! = 7 are shown.

A comparison network is composed solely of wires and comparators. A compara-tor, shown in Figure 27.1(a), is a device with two inputs, x and y, and two outputs,x ! and y!, that performs the following function:

x ! = min(x, y) ,

y! = max(x, y) .

Because the pictorial representation of a comparator in Figure 27.1(a) is toobulky for our purposes, we shall adopt the convention of drawing comparators assingle vertical lines, as shown in Figure 27.1(b). Inputs appear on the left andoutputs on the right, with the smaller input value appearing on the top output andthe larger input value appearing on the bottom output. We can thus think of acomparator as sorting its two inputs.

We shall assume that each comparator operates in O(1) time. In other words,we assume that the time between the appearance of the input values x and y andthe production of the output values x ! and y! is a constant.

A wire transmits a value from place to place. Wires can connect the outputof one comparator to the input of another, but otherwise they are either networkinput wires or network output wires. Throughout this chapter, we shall assumethat a comparison network contains n input wires a1, a2, . . . , an , through whichthe values to be sorted enter the network, and n output wires b1, b2, . . . , bn , whichproduce the results computed by the network. Also, we shall speak of the inputsequence "a1, a2, . . . , an# and the output sequence "b1, b2, . . . , bn#, referring tothe values on the input and output wires. That is, we use the same name for both awire and the value it carries. Our intention will always be clear from the context.

Figure 27.2 shows a comparison network, which is a set of comparators inter-connected by wires. We draw a comparison network on n inputs as a collectionof n horizontal lines with comparators stretched vertically. Note that a line doesnot represent a single wire, but rather a sequence of distinct wires connecting vari-ous comparators. The top line in Figure 27.2, for example, represents three wires:input wire a1, which connects to an input of comparator A; a wire connecting thetop output of comparator A to an input of comparator C; and output wire b1, whichcomes from the top output of comparator C . Each comparator input is connected

operates in O(1)

Convention: use the same name for both a wire and its value.

A sorting network is a comparison network whichworks correctly (that is, it sorts every input)

I. Course Intro and Sorting Networks Introduction to Sorting Networks 12

Page 26: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Comparison Networks

A comparison network consists solely of wires and comparators:comparator is a device with, on given two inputs, x and y , returns twooutputs x ′ = min(x , y) and y ′ = max(x , y)wire connect output of one comparator to the input of anotherspecial wires: n input wires a1, a2, . . . , an and n output wires b1, b2, . . . , bn

Comparison Network

27.1 Comparison networks 705

comparator

(a) (b)

7

3

3

7 xx

yy

x ! = min(x, y)x ! = min(x, y)

y! = max(x, y)y! = max(x, y)

Figure 27.1 (a) A comparator with inputs x and y and outputs x ! and y!. (b) The same comparator,drawn as a single vertical line. Inputs x = 7, y = 3 and outputs x ! = 3, y! = 7 are shown.

A comparison network is composed solely of wires and comparators. A compara-tor, shown in Figure 27.1(a), is a device with two inputs, x and y, and two outputs,x ! and y!, that performs the following function:

x ! = min(x, y) ,

y! = max(x, y) .

Because the pictorial representation of a comparator in Figure 27.1(a) is toobulky for our purposes, we shall adopt the convention of drawing comparators assingle vertical lines, as shown in Figure 27.1(b). Inputs appear on the left andoutputs on the right, with the smaller input value appearing on the top output andthe larger input value appearing on the bottom output. We can thus think of acomparator as sorting its two inputs.

We shall assume that each comparator operates in O(1) time. In other words,we assume that the time between the appearance of the input values x and y andthe production of the output values x ! and y! is a constant.

A wire transmits a value from place to place. Wires can connect the outputof one comparator to the input of another, but otherwise they are either networkinput wires or network output wires. Throughout this chapter, we shall assumethat a comparison network contains n input wires a1, a2, . . . , an , through whichthe values to be sorted enter the network, and n output wires b1, b2, . . . , bn , whichproduce the results computed by the network. Also, we shall speak of the inputsequence "a1, a2, . . . , an# and the output sequence "b1, b2, . . . , bn#, referring tothe values on the input and output wires. That is, we use the same name for both awire and the value it carries. Our intention will always be clear from the context.

Figure 27.2 shows a comparison network, which is a set of comparators inter-connected by wires. We draw a comparison network on n inputs as a collectionof n horizontal lines with comparators stretched vertically. Note that a line doesnot represent a single wire, but rather a sequence of distinct wires connecting vari-ous comparators. The top line in Figure 27.2, for example, represents three wires:input wire a1, which connects to an input of comparator A; a wire connecting thetop output of comparator A to an input of comparator C; and output wire b1, whichcomes from the top output of comparator C . Each comparator input is connected

operates in O(1)

Convention: use the same name for both a wire and its value.

A sorting network is a comparison network whichworks correctly (that is, it sorts every input)

I. Course Intro and Sorting Networks Introduction to Sorting Networks 12

Page 27: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Comparison Networks

A comparison network consists solely of wires and comparators:comparator is a device with, on given two inputs, x and y , returns twooutputs x ′ = min(x , y) and y ′ = max(x , y)wire connect output of one comparator to the input of anotherspecial wires: n input wires a1, a2, . . . , an and n output wires b1, b2, . . . , bn

Comparison Network

27.1 Comparison networks 705

comparator

(a) (b)

7

3

3

7 xx

yy

x ! = min(x, y)x ! = min(x, y)

y! = max(x, y)y! = max(x, y)

Figure 27.1 (a) A comparator with inputs x and y and outputs x ! and y!. (b) The same comparator,drawn as a single vertical line. Inputs x = 7, y = 3 and outputs x ! = 3, y! = 7 are shown.

A comparison network is composed solely of wires and comparators. A compara-tor, shown in Figure 27.1(a), is a device with two inputs, x and y, and two outputs,x ! and y!, that performs the following function:

x ! = min(x, y) ,

y! = max(x, y) .

Because the pictorial representation of a comparator in Figure 27.1(a) is toobulky for our purposes, we shall adopt the convention of drawing comparators assingle vertical lines, as shown in Figure 27.1(b). Inputs appear on the left andoutputs on the right, with the smaller input value appearing on the top output andthe larger input value appearing on the bottom output. We can thus think of acomparator as sorting its two inputs.

We shall assume that each comparator operates in O(1) time. In other words,we assume that the time between the appearance of the input values x and y andthe production of the output values x ! and y! is a constant.

A wire transmits a value from place to place. Wires can connect the outputof one comparator to the input of another, but otherwise they are either networkinput wires or network output wires. Throughout this chapter, we shall assumethat a comparison network contains n input wires a1, a2, . . . , an , through whichthe values to be sorted enter the network, and n output wires b1, b2, . . . , bn , whichproduce the results computed by the network. Also, we shall speak of the inputsequence "a1, a2, . . . , an# and the output sequence "b1, b2, . . . , bn#, referring tothe values on the input and output wires. That is, we use the same name for both awire and the value it carries. Our intention will always be clear from the context.

Figure 27.2 shows a comparison network, which is a set of comparators inter-connected by wires. We draw a comparison network on n inputs as a collectionof n horizontal lines with comparators stretched vertically. Note that a line doesnot represent a single wire, but rather a sequence of distinct wires connecting vari-ous comparators. The top line in Figure 27.2, for example, represents three wires:input wire a1, which connects to an input of comparator A; a wire connecting thetop output of comparator A to an input of comparator C; and output wire b1, whichcomes from the top output of comparator C . Each comparator input is connected

operates in O(1)

Convention: use the same name for both a wire and its value.

A sorting network is a comparison network whichworks correctly (that is, it sorts every input)

I. Course Intro and Sorting Networks Introduction to Sorting Networks 12

Page 28: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Comparison Networks

A comparison network consists solely of wires and comparators:comparator is a device with, on given two inputs, x and y , returns twooutputs x ′ = min(x , y) and y ′ = max(x , y)wire connect output of one comparator to the input of anotherspecial wires: n input wires a1, a2, . . . , an and n output wires b1, b2, . . . , bn

Comparison Network

27.1 Comparison networks 705

comparator

(a) (b)

7

3

3

7 xx

yy

x ! = min(x, y)x ! = min(x, y)

y! = max(x, y)y! = max(x, y)

Figure 27.1 (a) A comparator with inputs x and y and outputs x ! and y!. (b) The same comparator,drawn as a single vertical line. Inputs x = 7, y = 3 and outputs x ! = 3, y! = 7 are shown.

A comparison network is composed solely of wires and comparators. A compara-tor, shown in Figure 27.1(a), is a device with two inputs, x and y, and two outputs,x ! and y!, that performs the following function:

x ! = min(x, y) ,

y! = max(x, y) .

Because the pictorial representation of a comparator in Figure 27.1(a) is toobulky for our purposes, we shall adopt the convention of drawing comparators assingle vertical lines, as shown in Figure 27.1(b). Inputs appear on the left andoutputs on the right, with the smaller input value appearing on the top output andthe larger input value appearing on the bottom output. We can thus think of acomparator as sorting its two inputs.

We shall assume that each comparator operates in O(1) time. In other words,we assume that the time between the appearance of the input values x and y andthe production of the output values x ! and y! is a constant.

A wire transmits a value from place to place. Wires can connect the outputof one comparator to the input of another, but otherwise they are either networkinput wires or network output wires. Throughout this chapter, we shall assumethat a comparison network contains n input wires a1, a2, . . . , an , through whichthe values to be sorted enter the network, and n output wires b1, b2, . . . , bn , whichproduce the results computed by the network. Also, we shall speak of the inputsequence "a1, a2, . . . , an# and the output sequence "b1, b2, . . . , bn#, referring tothe values on the input and output wires. That is, we use the same name for both awire and the value it carries. Our intention will always be clear from the context.

Figure 27.2 shows a comparison network, which is a set of comparators inter-connected by wires. We draw a comparison network on n inputs as a collectionof n horizontal lines with comparators stretched vertically. Note that a line doesnot represent a single wire, but rather a sequence of distinct wires connecting vari-ous comparators. The top line in Figure 27.2, for example, represents three wires:input wire a1, which connects to an input of comparator A; a wire connecting thetop output of comparator A to an input of comparator C; and output wire b1, whichcomes from the top output of comparator C . Each comparator input is connected

operates in O(1)

Convention: use the same name for both a wire and its value.

A sorting network is a comparison network whichworks correctly (that is, it sorts every input)

I. Course Intro and Sorting Networks Introduction to Sorting Networks 12

Page 29: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 30: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 31: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 32: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 33: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 34: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 35: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

F

FF

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 36: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

F

FF

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 37: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

DD

D

DD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

F

FF

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 38: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

DD

D

D

D

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

F

FF

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 39: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

DD

DD

D

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

F

FF

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 40: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

DD

DD

D

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

F

F

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 41: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

F

FF

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 42: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 43: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 44: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 45: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 46: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 47: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 48: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 49: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 50: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 51: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 52: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 53: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 54: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)

This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 55: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)

This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 56: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:

Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 57: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 58: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 59: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth

0 1 1 2 2 3

Depth of a wire:Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 60: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0

1 1 2 2 3

Depth of a wire:Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 61: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1

1 2 2 3

Depth of a wire:Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 62: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1

2 2 3

Depth of a wire:Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 63: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2

2 3

Depth of a wire:Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 64: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2

3

Depth of a wire:Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 65: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 66: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Example of a Comparison Network (Figure 27.2)

a1 b1

a2 b2

a3 b3

a4 b4

D

D

DDD

A

B

C

E

A horizontal line representsa sequence of distinct wires

9

5

2

6

5

9

2

6

2

6

5

9

2

5

6

9

This network is in fact a sorting network (Exercise)This network would not be a sorting network (Why??)

depth 0 1 1 2 2 3

Depth of a wire:Input wire has depth 0

If a comparator has two inputs of depths dx and dy , then outputs havedepth max{dx , dy}+ 1

Maximum depth of an outputwire equals total running time

Interconnections between comparatorsmust be acyclic

X

Tracing back a path must never cycle back onitself and go through the same comparator twice.

FF

F

I. Course Intro and Sorting Networks Introduction to Sorting Networks 13

Page 67: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Zero-One Principle

Zero-One Principle: A sorting networks works correctly on arbitrary in-puts if it works correctly on binary inputs.

If a comparison network transforms the input a = 〈a1, a2, . . . , an〉 intothe output b = 〈b1, b2, . . . , bn〉, then for any monotonically increasingfunction f , the network transforms f (a) = 〈f (a1), f (a2), . . . , f (an)〉 intof (b) = 〈f (b1), f (b2), . . . , f (bn)〉.

Lemma 27.1

I. Course Intro and Sorting Networks Introduction to Sorting Networks 14

Page 68: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Zero-One Principle

Zero-One Principle: A sorting networks works correctly on arbitrary in-puts if it works correctly on binary inputs.

If a comparison network transforms the input a = 〈a1, a2, . . . , an〉 intothe output b = 〈b1, b2, . . . , bn〉, then for any monotonically increasingfunction f , the network transforms f (a) = 〈f (a1), f (a2), . . . , f (an)〉 intof (b) = 〈f (b1), f (b2), . . . , f (bn)〉.

Lemma 27.1

I. Course Intro and Sorting Networks Introduction to Sorting Networks 14

Page 69: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Zero-One Principle

Zero-One Principle: A sorting networks works correctly on arbitrary in-puts if it works correctly on binary inputs.

If a comparison network transforms the input a = 〈a1, a2, . . . , an〉 intothe output b = 〈b1, b2, . . . , bn〉, then for any monotonically increasingfunction f , the network transforms f (a) = 〈f (a1), f (a2), . . . , f (an)〉 intof (b) = 〈f (b1), f (b2), . . . , f (bn)〉.

Lemma 27.1

a bNetwork

f(a) f(b)Network

f f

710 Chapter 27 Sorting Networks

f (x)

f (y)

min( f (x), f (y)) = f (min(x, y))

max( f (x), f (y)) = f (max(x, y))

Figure 27.4 The operation of the comparator in the proof of Lemma 27.1. The function f ismonotonically increasing.

To prove the claim, consider a comparator whose input values are x and y. Theupper output of the comparator is min(x, y) and the lower output is max(x, y).Suppose we now apply f (x) and f (y) to the inputs of the comparator, as is shownin Figure 27.4. The operation of the comparator yields the value min( f (x), f (y))on the upper output and the value max( f (x), f (y)) on the lower output. Since fis monotonically increasing, x ! y implies f (x) ! f (y). Consequently, we havethe identities

min( f (x), f (y)) = f (min(x, y)) ,

max( f (x), f (y)) = f (max(x, y)) .

Thus, the comparator produces the values f (min(x, y)) and f (max(x, y)) whenf (x) and f (y) are its inputs, which completes the proof of the claim.We can use induction on the depth of each wire in a general comparison network

to prove a stronger result than the statement of the lemma: if a wire assumes thevalue ai when the input sequence a is applied to the network, then it assumes thevalue f (ai) when the input sequence f (a) is applied. Because the output wires areincluded in this statement, proving it will prove the lemma.For the basis, consider a wire at depth 0, that is, an input wire ai . The result

follows trivially: when f (a) is applied to the network, the input wire carries f (ai).For the inductive step, consider a wire at depth d, where d " 1. The wire is theoutput of a comparator at depth d, and the input wires to this comparator are at adepth strictly less than d. By the inductive hypothesis, therefore, if the input wiresto the comparator carry values ai and a j when the input sequence a is applied,then they carry f (ai ) and f (a j ) when the input sequence f (a) is applied. Byour earlier claim, the output wires of this comparator then carry f (min(ai , a j ))and f (max(ai , a j )). Since they carry min(ai , a j ) and max(ai , a j ) when the inputsequence is a, the lemma is proved.

As an example of the application of Lemma 27.1, Figure 27.5(b) shows the sort-ing network from Figure 27.2 (repeated in Figure 27.5(a)) with the monotonicallyincreasing function f (x) = #x/2$ applied to the inputs. The value on every wireis f applied to the value on the same wire in Figure 27.2.When a comparison network is a sorting network, Lemma 27.1 allows us to

prove the following remarkable result.

I. Course Intro and Sorting Networks Introduction to Sorting Networks 14

Page 70: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Zero-One Principle

Zero-One Principle: A sorting networks works correctly on arbitrary in-puts if it works correctly on binary inputs.

If a comparison network transforms the input a = 〈a1, a2, . . . , an〉 intothe output b = 〈b1, b2, . . . , bn〉, then for any monotonically increasingfunction f , the network transforms f (a) = 〈f (a1), f (a2), . . . , f (an)〉 intof (b) = 〈f (b1), f (b2), . . . , f (bn)〉.

Lemma 27.1

If a comparison network with n inputs sorts all 2n possible sequencesof 0’s and 1’s correctly, then it sorts all sequences of arbitrary numberscorrectly.

Theorem 27.2 (Zero-One Principle)

I. Course Intro and Sorting Networks Introduction to Sorting Networks 14

Page 71: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of the Zero-One Principle

If a comparison network with n inputs sorts all 2n possible sequencesof 0’s and 1’s correctly, then it sorts all sequences of arbitrary numberscorrectly.

Theorem 27.2 (Zero-One Principle)

Proof:

For the sake of contradiction, suppose the network does not correctly sort.

Let a = 〈a1, a2, . . . , an〉 be the input with ai < aj , but the network places aj

before ai in the output

Define a monotonically increasing function f as:

f (x) =

{0 if x ≤ ai ,1 if x > ai .

Since the network places aj before ai , by the previous lemma

⇒ f (aj ) is placed before f (ai )

But f (aj ) = 1 and f (ai ) = 0, which contradicts the assumption that thenetwork sorts all sequences of 0’s and 1’s correctly

I. Course Intro and Sorting Networks Introduction to Sorting Networks 15

Page 72: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of the Zero-One Principle

If a comparison network with n inputs sorts all 2n possible sequencesof 0’s and 1’s correctly, then it sorts all sequences of arbitrary numberscorrectly.

Theorem 27.2 (Zero-One Principle)

Proof:

For the sake of contradiction, suppose the network does not correctly sort.

Let a = 〈a1, a2, . . . , an〉 be the input with ai < aj , but the network places aj

before ai in the output

Define a monotonically increasing function f as:

f (x) =

{0 if x ≤ ai ,1 if x > ai .

Since the network places aj before ai , by the previous lemma

⇒ f (aj ) is placed before f (ai )

But f (aj ) = 1 and f (ai ) = 0, which contradicts the assumption that thenetwork sorts all sequences of 0’s and 1’s correctly

I. Course Intro and Sorting Networks Introduction to Sorting Networks 15

Page 73: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of the Zero-One Principle

If a comparison network with n inputs sorts all 2n possible sequencesof 0’s and 1’s correctly, then it sorts all sequences of arbitrary numberscorrectly.

Theorem 27.2 (Zero-One Principle)

Proof:

For the sake of contradiction, suppose the network does not correctly sort.

Let a = 〈a1, a2, . . . , an〉 be the input with ai < aj , but the network places aj

before ai in the output

Define a monotonically increasing function f as:

f (x) =

{0 if x ≤ ai ,1 if x > ai .

Since the network places aj before ai , by the previous lemma

⇒ f (aj ) is placed before f (ai )

But f (aj ) = 1 and f (ai ) = 0, which contradicts the assumption that thenetwork sorts all sequences of 0’s and 1’s correctly

I. Course Intro and Sorting Networks Introduction to Sorting Networks 15

Page 74: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of the Zero-One Principle

If a comparison network with n inputs sorts all 2n possible sequencesof 0’s and 1’s correctly, then it sorts all sequences of arbitrary numberscorrectly.

Theorem 27.2 (Zero-One Principle)

Proof:

For the sake of contradiction, suppose the network does not correctly sort.

Let a = 〈a1, a2, . . . , an〉 be the input with ai < aj , but the network places aj

before ai in the output

Define a monotonically increasing function f as:

f (x) =

{0 if x ≤ ai ,1 if x > ai .

Since the network places aj before ai , by the previous lemma

⇒ f (aj ) is placed before f (ai )

But f (aj ) = 1 and f (ai ) = 0, which contradicts the assumption that thenetwork sorts all sequences of 0’s and 1’s correctly

I. Course Intro and Sorting Networks Introduction to Sorting Networks 15

Page 75: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of the Zero-One Principle

If a comparison network with n inputs sorts all 2n possible sequencesof 0’s and 1’s correctly, then it sorts all sequences of arbitrary numberscorrectly.

Theorem 27.2 (Zero-One Principle)

Proof:

For the sake of contradiction, suppose the network does not correctly sort.

Let a = 〈a1, a2, . . . , an〉 be the input with ai < aj , but the network places aj

before ai in the output

Define a monotonically increasing function f as:

f (x) =

{0 if x ≤ ai ,1 if x > ai .

Since the network places aj before ai , by the previous lemma

⇒ f (aj ) is placed before f (ai )

But f (aj ) = 1 and f (ai ) = 0, which contradicts the assumption that thenetwork sorts all sequences of 0’s and 1’s correctly

I. Course Intro and Sorting Networks Introduction to Sorting Networks 15

Page 76: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of the Zero-One Principle

If a comparison network with n inputs sorts all 2n possible sequencesof 0’s and 1’s correctly, then it sorts all sequences of arbitrary numberscorrectly.

Theorem 27.2 (Zero-One Principle)

Proof:

For the sake of contradiction, suppose the network does not correctly sort.

Let a = 〈a1, a2, . . . , an〉 be the input with ai < aj , but the network places aj

before ai in the output

Define a monotonically increasing function f as:

f (x) =

{0 if x ≤ ai ,1 if x > ai .

Since the network places aj before ai , by the previous lemma

⇒ f (aj ) is placed before f (ai )

But f (aj ) = 1 and f (ai ) = 0, which contradicts the assumption that thenetwork sorts all sequences of 0’s and 1’s correctly

I. Course Intro and Sorting Networks Introduction to Sorting Networks 15

Page 77: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of the Zero-One Principle

If a comparison network with n inputs sorts all 2n possible sequencesof 0’s and 1’s correctly, then it sorts all sequences of arbitrary numberscorrectly.

Theorem 27.2 (Zero-One Principle)

Proof:

For the sake of contradiction, suppose the network does not correctly sort.

Let a = 〈a1, a2, . . . , an〉 be the input with ai < aj , but the network places aj

before ai in the output

Define a monotonically increasing function f as:

f (x) =

{0 if x ≤ ai ,1 if x > ai .

Since the network places aj before ai , by the previous lemma

⇒ f (aj ) is placed before f (ai )

But f (aj ) = 1 and f (ai ) = 0, which contradicts the assumption that thenetwork sorts all sequences of 0’s and 1’s correctly

I. Course Intro and Sorting Networks Introduction to Sorting Networks 15

Page 78: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of the Zero-One Principle

If a comparison network with n inputs sorts all 2n possible sequencesof 0’s and 1’s correctly, then it sorts all sequences of arbitrary numberscorrectly.

Theorem 27.2 (Zero-One Principle)

Proof:

For the sake of contradiction, suppose the network does not correctly sort.

Let a = 〈a1, a2, . . . , an〉 be the input with ai < aj , but the network places aj

before ai in the output

Define a monotonically increasing function f as:

f (x) =

{0 if x ≤ ai ,1 if x > ai .

Since the network places aj before ai , by the previous lemma⇒ f (aj ) is placed before f (ai )

But f (aj ) = 1 and f (ai ) = 0, which contradicts the assumption that thenetwork sorts all sequences of 0’s and 1’s correctly

I. Course Intro and Sorting Networks Introduction to Sorting Networks 15

Page 79: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of the Zero-One Principle

If a comparison network with n inputs sorts all 2n possible sequencesof 0’s and 1’s correctly, then it sorts all sequences of arbitrary numberscorrectly.

Theorem 27.2 (Zero-One Principle)

Proof:

For the sake of contradiction, suppose the network does not correctly sort.

Let a = 〈a1, a2, . . . , an〉 be the input with ai < aj , but the network places aj

before ai in the output

Define a monotonically increasing function f as:

f (x) =

{0 if x ≤ ai ,1 if x > ai .

Since the network places aj before ai , by the previous lemma⇒ f (aj ) is placed before f (ai )

But f (aj ) = 1 and f (ai ) = 0, which contradicts the assumption that thenetwork sorts all sequences of 0’s and 1’s correctly

I. Course Intro and Sorting Networks Introduction to Sorting Networks 15

Page 80: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Some Basic (Recursive) Sorting Networks

12345

n − 1n

n + 1

n-wire Sorting Network ???

Bubble Sort

12345

n − 1n

n + 1

n-wire Sorting Network

???Insertion Sort

These are Sorting Networks, but with depth Θ(n).

I. Course Intro and Sorting Networks Introduction to Sorting Networks 16

Page 81: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Some Basic (Recursive) Sorting Networks

12345

n − 1n

n + 1

n-wire Sorting Network

???

Bubble Sort

12345

n − 1n

n + 1

n-wire Sorting Network

???Insertion Sort

These are Sorting Networks, but with depth Θ(n).

I. Course Intro and Sorting Networks Introduction to Sorting Networks 16

Page 82: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Some Basic (Recursive) Sorting Networks

12345

n − 1n

n + 1

n-wire Sorting Network

???

Bubble Sort

12345

n − 1n

n + 1

n-wire Sorting Network ???

Insertion Sort

These are Sorting Networks, but with depth Θ(n).

I. Course Intro and Sorting Networks Introduction to Sorting Networks 16

Page 83: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Some Basic (Recursive) Sorting Networks

12345

n − 1n

n + 1

n-wire Sorting Network

???

Bubble Sort

12345

n − 1n

n + 1

n-wire Sorting Network

???

Insertion Sort

These are Sorting Networks, but with depth Θ(n).

I. Course Intro and Sorting Networks Introduction to Sorting Networks 16

Page 84: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Some Basic (Recursive) Sorting Networks

12345

n − 1n

n + 1

n-wire Sorting Network

???

Bubble Sort

12345

n − 1n

n + 1

n-wire Sorting Network

???

Insertion Sort

These are Sorting Networks, but with depth Θ(n).

I. Course Intro and Sorting Networks Introduction to Sorting Networks 16

Page 85: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Outline

Outline of this Course

Some Highlights

Introduction to Sorting Networks

Batcher’s Sorting Network

Counting Networks

Load Balancing on Graphs

I. Course Intro and Sorting Networks Batcher’s Sorting Network 17

Page 86: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉〈6, 9, 4, 2, 3, 5〉〈9, 8, 3, 2, 4, 6〉

binary sequences:

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 87: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉〈6, 9, 4, 2, 3, 5〉〈9, 8, 3, 2, 4, 6〉

binary sequences:

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 88: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉〈6, 9, 4, 2, 3, 5〉〈9, 8, 3, 2, 4, 6〉

binary sequences:

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 89: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉 ?

〈6, 9, 4, 2, 3, 5〉〈9, 8, 3, 2, 4, 6〉

binary sequences:

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 90: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉 X

〈6, 9, 4, 2, 3, 5〉〈9, 8, 3, 2, 4, 6〉

binary sequences:

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 91: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉 X〈6, 9, 4, 2, 3, 5〉 ?

〈9, 8, 3, 2, 4, 6〉

binary sequences:

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 92: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉 X〈6, 9, 4, 2, 3, 5〉 X

〈9, 8, 3, 2, 4, 6〉

binary sequences:

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 93: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉 X〈6, 9, 4, 2, 3, 5〉 X〈9, 8, 3, 2, 4, 6〉 ?

binary sequences:

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 94: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉 X〈6, 9, 4, 2, 3, 5〉 X〈9, 8, 3, 2, 4, 6〉 X

binary sequences:

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 95: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉 X〈6, 9, 4, 2, 3, 5〉 X〈9, 8, 3, 2, 4, 6〉 X〈4, 5, 7, 1, 2, 6〉 ?

binary sequences:

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 96: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉 X〈6, 9, 4, 2, 3, 5〉 X〈9, 8, 3, 2, 4, 6〉 X

((((((〈4, 5, 7, 1, 2, 6〉

binary sequences:

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 97: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉 X〈6, 9, 4, 2, 3, 5〉 X〈9, 8, 3, 2, 4, 6〉 X

((((((〈4, 5, 7, 1, 2, 6〉binary sequences: ?

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 98: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Sequences

A sequence is bitonic if it monotonically increases and then monoton-ically decreases, or can be circularly shifted to become monotonicallyincreasing and then monotonically decreasing.

Bitonic Sequence

Sequences of one or two numbers are defined to be bitonic.

Examples:

〈1, 4, 6, 8, 3, 2〉 X〈6, 9, 4, 2, 3, 5〉 X〈9, 8, 3, 2, 4, 6〉 X

((((((〈4, 5, 7, 1, 2, 6〉binary sequences: 0i1j0k , or, 1i0j1k , for i, j, k ≥ 0.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 18

Page 99: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Towards Bitonic Sorting Networks

A half-cleaner is a comparison network of depth 1 in which input wire i iscompared with wire i + n/2 for i = 1, 2, . . . , n/2.

Half-Cleaner

We always assume that n is even.

If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then theoutput satisfies the following properties:

both the top half and the bottom half are bitonic,

every element in the top is not larger than any element in the bottom,

at least one half is clean.

Lemma 27.3

27.3 A bitonic sorting network 713

0011100

0000101

0 1

bitonic

bitonic,clean

bitonic

0011111

0010111

0 1

bitonic

bitonic,clean

bitonic

Figure 27.7 The comparison network HALF-CLEANER[8]. Two different sample zero-one inputand output values are shown. The input is assumed to be bitonic. A half-cleaner ensures that ev-ery output element of the top half is at least as small as every output element of the bottom half.Moreover, both halves are bitonic, and at least one half is clean.

even.) Figure 27.7 shows HALF-CLEANER[8], the half-cleaner with 8 inputs and8 outputs.When a bitonic sequence of 0’s and 1’s is applied as input to a half-cleaner, the

half-cleaner produces an output sequence in which smaller values are in the tophalf, larger values are in the bottom half, and both halves are bitonic. In fact, atleast one of the halves is clean—consisting of either all 0’s or all 1’s—and it is fromthis property that we derive the name “half-cleaner.” (Note that all clean sequencesare bitonic.) The next lemma proves these properties of half-cleaners.

Lemma 27.3If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then the outputsatisfies the following properties: both the top half and the bottom half are bitonic,every element in the top half is at least as small as every element of the bottomhalf, and at least one half is clean.

Proof The comparison network HALF-CLEANER[n] compares inputs i andi + n/2 for i = 1, 2, . . . , n/2. Without loss of generality, suppose that the in-put is of the form 00 . . . 011 . . . 100 . . . 0. (The situation in which the input is ofthe form 11 . . . 100 . . . 011 . . . 1 is symmetric.) There are three possible cases de-pending upon the block of consecutive 0’s or 1’s in which the midpoint n/2 falls,and one of these cases (the one in which the midpoint occurs in the block of 1’s) isfurther split into two cases. The four cases are shown in Figure 27.8. In each caseshown, the lemma holds.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 19

Page 100: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Towards Bitonic Sorting Networks

A half-cleaner is a comparison network of depth 1 in which input wire i iscompared with wire i + n/2 for i = 1, 2, . . . , n/2.

Half-Cleaner

We always assume that n is even.

If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then theoutput satisfies the following properties:

both the top half and the bottom half are bitonic,

every element in the top is not larger than any element in the bottom,

at least one half is clean.

Lemma 27.3

27.3 A bitonic sorting network 713

0011100

0000101

0 1

bitonic

bitonic,clean

bitonic

0011111

0010111

0 1

bitonic

bitonic,clean

bitonic

Figure 27.7 The comparison network HALF-CLEANER[8]. Two different sample zero-one inputand output values are shown. The input is assumed to be bitonic. A half-cleaner ensures that ev-ery output element of the top half is at least as small as every output element of the bottom half.Moreover, both halves are bitonic, and at least one half is clean.

even.) Figure 27.7 shows HALF-CLEANER[8], the half-cleaner with 8 inputs and8 outputs.When a bitonic sequence of 0’s and 1’s is applied as input to a half-cleaner, the

half-cleaner produces an output sequence in which smaller values are in the tophalf, larger values are in the bottom half, and both halves are bitonic. In fact, atleast one of the halves is clean—consisting of either all 0’s or all 1’s—and it is fromthis property that we derive the name “half-cleaner.” (Note that all clean sequencesare bitonic.) The next lemma proves these properties of half-cleaners.

Lemma 27.3If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then the outputsatisfies the following properties: both the top half and the bottom half are bitonic,every element in the top half is at least as small as every element of the bottomhalf, and at least one half is clean.

Proof The comparison network HALF-CLEANER[n] compares inputs i andi + n/2 for i = 1, 2, . . . , n/2. Without loss of generality, suppose that the in-put is of the form 00 . . . 011 . . . 100 . . . 0. (The situation in which the input is ofthe form 11 . . . 100 . . . 011 . . . 1 is symmetric.) There are three possible cases de-pending upon the block of consecutive 0’s or 1’s in which the midpoint n/2 falls,and one of these cases (the one in which the midpoint occurs in the block of 1’s) isfurther split into two cases. The four cases are shown in Figure 27.8. In each caseshown, the lemma holds.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 19

Page 101: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Towards Bitonic Sorting Networks

A half-cleaner is a comparison network of depth 1 in which input wire i iscompared with wire i + n/2 for i = 1, 2, . . . , n/2.

Half-Cleaner

We always assume that n is even.

If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then theoutput satisfies the following properties:

both the top half and the bottom half are bitonic,

every element in the top is not larger than any element in the bottom,

at least one half is clean.

Lemma 27.3

27.3 A bitonic sorting network 713

0011100

0000101

0 1

bitonic

bitonic,clean

bitonic

0011111

0010111

0 1

bitonic

bitonic,clean

bitonic

Figure 27.7 The comparison network HALF-CLEANER[8]. Two different sample zero-one inputand output values are shown. The input is assumed to be bitonic. A half-cleaner ensures that ev-ery output element of the top half is at least as small as every output element of the bottom half.Moreover, both halves are bitonic, and at least one half is clean.

even.) Figure 27.7 shows HALF-CLEANER[8], the half-cleaner with 8 inputs and8 outputs.When a bitonic sequence of 0’s and 1’s is applied as input to a half-cleaner, the

half-cleaner produces an output sequence in which smaller values are in the tophalf, larger values are in the bottom half, and both halves are bitonic. In fact, atleast one of the halves is clean—consisting of either all 0’s or all 1’s—and it is fromthis property that we derive the name “half-cleaner.” (Note that all clean sequencesare bitonic.) The next lemma proves these properties of half-cleaners.

Lemma 27.3If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then the outputsatisfies the following properties: both the top half and the bottom half are bitonic,every element in the top half is at least as small as every element of the bottomhalf, and at least one half is clean.

Proof The comparison network HALF-CLEANER[n] compares inputs i andi + n/2 for i = 1, 2, . . . , n/2. Without loss of generality, suppose that the in-put is of the form 00 . . . 011 . . . 100 . . . 0. (The situation in which the input is ofthe form 11 . . . 100 . . . 011 . . . 1 is symmetric.) There are three possible cases de-pending upon the block of consecutive 0’s or 1’s in which the midpoint n/2 falls,and one of these cases (the one in which the midpoint occurs in the block of 1’s) isfurther split into two cases. The four cases are shown in Figure 27.8. In each caseshown, the lemma holds.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 19

Page 102: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Towards Bitonic Sorting Networks

A half-cleaner is a comparison network of depth 1 in which input wire i iscompared with wire i + n/2 for i = 1, 2, . . . , n/2.

Half-Cleaner

We always assume that n is even.

If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then theoutput satisfies the following properties:

both the top half and the bottom half are bitonic,

every element in the top is not larger than any element in the bottom,

at least one half is clean.

Lemma 27.3

27.3 A bitonic sorting network 713

0011100

0000101

0 1

bitonic

bitonic,clean

bitonic

0011111

0010111

0 1

bitonic

bitonic,clean

bitonic

Figure 27.7 The comparison network HALF-CLEANER[8]. Two different sample zero-one inputand output values are shown. The input is assumed to be bitonic. A half-cleaner ensures that ev-ery output element of the top half is at least as small as every output element of the bottom half.Moreover, both halves are bitonic, and at least one half is clean.

even.) Figure 27.7 shows HALF-CLEANER[8], the half-cleaner with 8 inputs and8 outputs.When a bitonic sequence of 0’s and 1’s is applied as input to a half-cleaner, the

half-cleaner produces an output sequence in which smaller values are in the tophalf, larger values are in the bottom half, and both halves are bitonic. In fact, atleast one of the halves is clean—consisting of either all 0’s or all 1’s—and it is fromthis property that we derive the name “half-cleaner.” (Note that all clean sequencesare bitonic.) The next lemma proves these properties of half-cleaners.

Lemma 27.3If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then the outputsatisfies the following properties: both the top half and the bottom half are bitonic,every element in the top half is at least as small as every element of the bottomhalf, and at least one half is clean.

Proof The comparison network HALF-CLEANER[n] compares inputs i andi + n/2 for i = 1, 2, . . . , n/2. Without loss of generality, suppose that the in-put is of the form 00 . . . 011 . . . 100 . . . 0. (The situation in which the input is ofthe form 11 . . . 100 . . . 011 . . . 1 is symmetric.) There are three possible cases de-pending upon the block of consecutive 0’s or 1’s in which the midpoint n/2 falls,and one of these cases (the one in which the midpoint occurs in the block of 1’s) isfurther split into two cases. The four cases are shown in Figure 27.8. In each caseshown, the lemma holds.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 19

Page 103: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Towards Bitonic Sorting Networks

A half-cleaner is a comparison network of depth 1 in which input wire i iscompared with wire i + n/2 for i = 1, 2, . . . , n/2.

Half-Cleaner

We always assume that n is even.

If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then theoutput satisfies the following properties:

both the top half and the bottom half are bitonic,

every element in the top is not larger than any element in the bottom,

at least one half is clean.

Lemma 27.3

27.3 A bitonic sorting network 713

0011100

0000101

0 1

bitonic

bitonic,clean

bitonic

0011111

0010111

0 1

bitonic

bitonic,clean

bitonic

Figure 27.7 The comparison network HALF-CLEANER[8]. Two different sample zero-one inputand output values are shown. The input is assumed to be bitonic. A half-cleaner ensures that ev-ery output element of the top half is at least as small as every output element of the bottom half.Moreover, both halves are bitonic, and at least one half is clean.

even.) Figure 27.7 shows HALF-CLEANER[8], the half-cleaner with 8 inputs and8 outputs.When a bitonic sequence of 0’s and 1’s is applied as input to a half-cleaner, the

half-cleaner produces an output sequence in which smaller values are in the tophalf, larger values are in the bottom half, and both halves are bitonic. In fact, atleast one of the halves is clean—consisting of either all 0’s or all 1’s—and it is fromthis property that we derive the name “half-cleaner.” (Note that all clean sequencesare bitonic.) The next lemma proves these properties of half-cleaners.

Lemma 27.3If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then the outputsatisfies the following properties: both the top half and the bottom half are bitonic,every element in the top half is at least as small as every element of the bottomhalf, and at least one half is clean.

Proof The comparison network HALF-CLEANER[n] compares inputs i andi + n/2 for i = 1, 2, . . . , n/2. Without loss of generality, suppose that the in-put is of the form 00 . . . 011 . . . 100 . . . 0. (The situation in which the input is ofthe form 11 . . . 100 . . . 011 . . . 1 is symmetric.) There are three possible cases de-pending upon the block of consecutive 0’s or 1’s in which the midpoint n/2 falls,and one of these cases (the one in which the midpoint occurs in the block of 1’s) isfurther split into two cases. The four cases are shown in Figure 27.8. In each caseshown, the lemma holds.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 19

Page 104: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Towards Bitonic Sorting Networks

A half-cleaner is a comparison network of depth 1 in which input wire i iscompared with wire i + n/2 for i = 1, 2, . . . , n/2.

Half-Cleaner

We always assume that n is even.

If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then theoutput satisfies the following properties:

both the top half and the bottom half are bitonic,

every element in the top is not larger than any element in the bottom,

at least one half is clean.

Lemma 27.3

27.3 A bitonic sorting network 713

0011100

0000101

0 1

bitonic

bitonic,clean

bitonic

0011111

0010111

0 1

bitonic

bitonic,clean

bitonic

Figure 27.7 The comparison network HALF-CLEANER[8]. Two different sample zero-one inputand output values are shown. The input is assumed to be bitonic. A half-cleaner ensures that ev-ery output element of the top half is at least as small as every output element of the bottom half.Moreover, both halves are bitonic, and at least one half is clean.

even.) Figure 27.7 shows HALF-CLEANER[8], the half-cleaner with 8 inputs and8 outputs.When a bitonic sequence of 0’s and 1’s is applied as input to a half-cleaner, the

half-cleaner produces an output sequence in which smaller values are in the tophalf, larger values are in the bottom half, and both halves are bitonic. In fact, atleast one of the halves is clean—consisting of either all 0’s or all 1’s—and it is fromthis property that we derive the name “half-cleaner.” (Note that all clean sequencesare bitonic.) The next lemma proves these properties of half-cleaners.

Lemma 27.3If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then the outputsatisfies the following properties: both the top half and the bottom half are bitonic,every element in the top half is at least as small as every element of the bottomhalf, and at least one half is clean.

Proof The comparison network HALF-CLEANER[n] compares inputs i andi + n/2 for i = 1, 2, . . . , n/2. Without loss of generality, suppose that the in-put is of the form 00 . . . 011 . . . 100 . . . 0. (The situation in which the input is ofthe form 11 . . . 100 . . . 011 . . . 1 is symmetric.) There are three possible cases de-pending upon the block of consecutive 0’s or 1’s in which the midpoint n/2 falls,and one of these cases (the one in which the midpoint occurs in the block of 1’s) isfurther split into two cases. The four cases are shown in Figure 27.8. In each caseshown, the lemma holds.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 19

Page 105: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Towards Bitonic Sorting Networks

A half-cleaner is a comparison network of depth 1 in which input wire i iscompared with wire i + n/2 for i = 1, 2, . . . , n/2.

Half-Cleaner

We always assume that n is even.

If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then theoutput satisfies the following properties:

both the top half and the bottom half are bitonic,

every element in the top is not larger than any element in the bottom,

at least one half is clean.

Lemma 27.3

27.3 A bitonic sorting network 713

0011100

0000101

0 1

bitonic

bitonic,clean

bitonic

0011111

0010111

0 1

bitonic

bitonic,clean

bitonic

Figure 27.7 The comparison network HALF-CLEANER[8]. Two different sample zero-one inputand output values are shown. The input is assumed to be bitonic. A half-cleaner ensures that ev-ery output element of the top half is at least as small as every output element of the bottom half.Moreover, both halves are bitonic, and at least one half is clean.

even.) Figure 27.7 shows HALF-CLEANER[8], the half-cleaner with 8 inputs and8 outputs.When a bitonic sequence of 0’s and 1’s is applied as input to a half-cleaner, the

half-cleaner produces an output sequence in which smaller values are in the tophalf, larger values are in the bottom half, and both halves are bitonic. In fact, atleast one of the halves is clean—consisting of either all 0’s or all 1’s—and it is fromthis property that we derive the name “half-cleaner.” (Note that all clean sequencesare bitonic.) The next lemma proves these properties of half-cleaners.

Lemma 27.3If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then the outputsatisfies the following properties: both the top half and the bottom half are bitonic,every element in the top half is at least as small as every element of the bottomhalf, and at least one half is clean.

Proof The comparison network HALF-CLEANER[n] compares inputs i andi + n/2 for i = 1, 2, . . . , n/2. Without loss of generality, suppose that the in-put is of the form 00 . . . 011 . . . 100 . . . 0. (The situation in which the input is ofthe form 11 . . . 100 . . . 011 . . . 1 is symmetric.) There are three possible cases de-pending upon the block of consecutive 0’s or 1’s in which the midpoint n/2 falls,and one of these cases (the one in which the midpoint occurs in the block of 1’s) isfurther split into two cases. The four cases are shown in Figure 27.8. In each caseshown, the lemma holds.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 19

Page 106: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Towards Bitonic Sorting Networks

A half-cleaner is a comparison network of depth 1 in which input wire i iscompared with wire i + n/2 for i = 1, 2, . . . , n/2.

Half-Cleaner

We always assume that n is even.

If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then theoutput satisfies the following properties:

both the top half and the bottom half are bitonic,

every element in the top is not larger than any element in the bottom,

at least one half is clean.

Lemma 27.3

27.3 A bitonic sorting network 713

0011100

0000101

0 1

bitonic

bitonic,clean

bitonic

0011111

0010111

0 1

bitonic

bitonic,clean

bitonic

Figure 27.7 The comparison network HALF-CLEANER[8]. Two different sample zero-one inputand output values are shown. The input is assumed to be bitonic. A half-cleaner ensures that ev-ery output element of the top half is at least as small as every output element of the bottom half.Moreover, both halves are bitonic, and at least one half is clean.

even.) Figure 27.7 shows HALF-CLEANER[8], the half-cleaner with 8 inputs and8 outputs.When a bitonic sequence of 0’s and 1’s is applied as input to a half-cleaner, the

half-cleaner produces an output sequence in which smaller values are in the tophalf, larger values are in the bottom half, and both halves are bitonic. In fact, atleast one of the halves is clean—consisting of either all 0’s or all 1’s—and it is fromthis property that we derive the name “half-cleaner.” (Note that all clean sequencesare bitonic.) The next lemma proves these properties of half-cleaners.

Lemma 27.3If the input to a half-cleaner is a bitonic sequence of 0’s and 1’s, then the outputsatisfies the following properties: both the top half and the bottom half are bitonic,every element in the top half is at least as small as every element of the bottomhalf, and at least one half is clean.

Proof The comparison network HALF-CLEANER[n] compares inputs i andi + n/2 for i = 1, 2, . . . , n/2. Without loss of generality, suppose that the in-put is of the form 00 . . . 011 . . . 100 . . . 0. (The situation in which the input is ofthe form 11 . . . 100 . . . 011 . . . 1 is symmetric.) There are three possible cases de-pending upon the block of consecutive 0’s or 1’s in which the midpoint n/2 falls,and one of these cases (the one in which the midpoint occurs in the block of 1’s) isfurther split into two cases. The four cases are shown in Figure 27.8. In each caseshown, the lemma holds.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 19

Page 107: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of Lemma 27.3

W.l.o.g. assume that the input is of the form 0i1j0k , for some i, j, k ≥ 0.

This suggests a recursive approach, since it nowsuffices to sort the top and bottom half separately.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 20

Page 108: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of Lemma 27.3

W.l.o.g. assume that the input is of the form 0i1j0k , for some i, j, k ≥ 0.714 Chapter 27 Sorting Networks

0

1

0

0

10

1 1

1

0 0

0

1

10

bitonic,clean

bitonic

bitonic

divide compare combine

top top

bottom bottom

(a)

0

1

0

1bitonic

top top

bottom bottom

(b)

0

1 0

1 0

01

0

01

1

0bitonic

top top

bottom bottom

(c)

0100

0

01

0

0

01

0

01

0bitonic

top top

bottom bottom

(d)

01 00

0

01

0

0

01

0

bitonic,clean

bitonic

bitonic,clean

bitonic

bitonic,clean

bitonic

1

0

Figure 27.8 The possible comparisons in HALF-CLEANER[n]. The input sequence is assumedto be a bitonic sequence of 0’s and 1’s, and without loss of generality, we assume that it is of theform 00 . . . 011 . . . 100 . . . 0. Subsequences of 0’s are white, and subsequences of 1’s are gray. Wecan think of the n inputs as being divided into two halves such that for i = 1, 2, . . . , n/2, inputs iand i + n/2 are compared. (a)–(b) Cases in which the division occurs in the middle subsequenceof 1’s. (c)–(d) Cases in which the division occurs in a subsequence of 0’s. For all cases, everyelement in the top half of the output is at least as small as every element in the bottom half, bothhalves are bitonic, and at least one half is clean.

This suggests a recursive approach, since it nowsuffices to sort the top and bottom half separately.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 20

Page 109: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of Lemma 27.3

W.l.o.g. assume that the input is of the form 0i1j0k , for some i, j, k ≥ 0.714 Chapter 27 Sorting Networks

0

1

0

0

10

1 1

1

0 0

0

1

10

bitonic,clean

bitonic

bitonic

divide compare combine

top top

bottom bottom

(a)

0

1

0

1bitonic

top top

bottom bottom

(b)

0

1 0

1 0

01

0

01

1

0bitonic

top top

bottom bottom

(c)

0100

0

01

0

0

01

0

01

0bitonic

top top

bottom bottom

(d)

01 00

0

01

0

0

01

0

bitonic,clean

bitonic

bitonic,clean

bitonic

bitonic,clean

bitonic

1

0

Figure 27.8 The possible comparisons in HALF-CLEANER[n]. The input sequence is assumedto be a bitonic sequence of 0’s and 1’s, and without loss of generality, we assume that it is of theform 00 . . . 011 . . . 100 . . . 0. Subsequences of 0’s are white, and subsequences of 1’s are gray. Wecan think of the n inputs as being divided into two halves such that for i = 1, 2, . . . , n/2, inputs iand i + n/2 are compared. (a)–(b) Cases in which the division occurs in the middle subsequenceof 1’s. (c)–(d) Cases in which the division occurs in a subsequence of 0’s. For all cases, everyelement in the top half of the output is at least as small as every element in the bottom half, bothhalves are bitonic, and at least one half is clean.

This suggests a recursive approach, since it nowsuffices to sort the top and bottom half separately.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 20

Page 110: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of Lemma 27.3

W.l.o.g. assume that the input is of the form 0i1j0k , for some i, j, k ≥ 0.

714 Chapter 27 Sorting Networks

0

1

0

0

10

1 1

1

0 0

0

1

10

bitonic,clean

bitonic

bitonic

divide compare combine

top top

bottom bottom

(a)

0

1

0

1bitonic

top top

bottom bottom

(b)

0

1 0

1 0

01

0

01

1

0bitonic

top top

bottom bottom

(c)

0100

0

01

0

0

01

0

01

0bitonic

top top

bottom bottom

(d)

01 00

0

01

0

0

01

0

bitonic,clean

bitonic

bitonic,clean

bitonic

bitonic,clean

bitonic

1

0

Figure 27.8 The possible comparisons in HALF-CLEANER[n]. The input sequence is assumedto be a bitonic sequence of 0’s and 1’s, and without loss of generality, we assume that it is of theform 00 . . . 011 . . . 100 . . . 0. Subsequences of 0’s are white, and subsequences of 1’s are gray. Wecan think of the n inputs as being divided into two halves such that for i = 1, 2, . . . , n/2, inputs iand i + n/2 are compared. (a)–(b) Cases in which the division occurs in the middle subsequenceof 1’s. (c)–(d) Cases in which the division occurs in a subsequence of 0’s. For all cases, everyelement in the top half of the output is at least as small as every element in the bottom half, bothhalves are bitonic, and at least one half is clean.

This suggests a recursive approach, since it nowsuffices to sort the top and bottom half separately.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 20

Page 111: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Proof of Lemma 27.3

W.l.o.g. assume that the input is of the form 0i1j0k , for some i, j, k ≥ 0.

714 Chapter 27 Sorting Networks

0

1

0

0

10

1 1

1

0 0

0

1

10

bitonic,clean

bitonic

bitonic

divide compare combine

top top

bottom bottom

(a)

0

1

0

1bitonic

top top

bottom bottom

(b)

0

1 0

1 0

01

0

01

1

0bitonic

top top

bottom bottom

(c)

0100

0

01

0

0

01

0

01

0bitonic

top top

bottom bottom

(d)

01 00

0

01

0

0

01

0

bitonic,clean

bitonic

bitonic,clean

bitonic

bitonic,clean

bitonic

1

0

Figure 27.8 The possible comparisons in HALF-CLEANER[n]. The input sequence is assumedto be a bitonic sequence of 0’s and 1’s, and without loss of generality, we assume that it is of theform 00 . . . 011 . . . 100 . . . 0. Subsequences of 0’s are white, and subsequences of 1’s are gray. Wecan think of the n inputs as being divided into two halves such that for i = 1, 2, . . . , n/2, inputs iand i + n/2 are compared. (a)–(b) Cases in which the division occurs in the middle subsequenceof 1’s. (c)–(d) Cases in which the division occurs in a subsequence of 0’s. For all cases, everyelement in the top half of the output is at least as small as every element in the bottom half, bothhalves are bitonic, and at least one half is clean.

This suggests a recursive approach, since it nowsuffices to sort the top and bottom half separately.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 20

Page 112: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

The Bitonic Sorter27.3 A bitonic sorting network 715

00001011

00001011

00111000

00000111

(b)(a)

bitonic sorted

BITONIC-SORTER[n/2]

HALF-CLEANER[n]

BITONIC-SORTER[n/2]

Figure 27.9 The comparison network BITONIC-SORTER[n], shown here for n = 8. (a) The re-cursive construction: HALF-CLEANER[n] followed by two copies of BITONIC-SORTER[n/2] thatoperate in parallel. (b) The network after unrolling the recursion. Each half-cleaner is shaded. Sam-ple zero-one values are shown on the wires.

The bitonic sorter

By recursively combining half-cleaners, as shown in Figure 27.9, we can builda bitonic sorter, which is a network that sorts bitonic sequences. The first stageof BITONIC-SORTER[n] consists of HALF-CLEANER[n], which, by Lemma 27.3,produces two bitonic sequences of half the size such that every element in thetop half is at least as small as every element in the bottom half. Thus, we cancomplete the sort by using two copies of BITONIC-SORTER[n/2] to sort the twohalves recursively. In Figure 27.9(a), the recursion has been shown explicitly, andin Figure 27.9(b), the recursion has been unrolled to show the progressively smallerhalf-cleaners that make up the remainder of the bitonic sorter. The depth D(n) ofBITONIC-SORTER[n] is given by the recurrence

D(n) =!0 if n = 1 ,D(n/2) + 1 if n = 2k and k ! 1 ,

whose solution is D(n) = lg n.Thus, a zero-one bitonic sequence can be sorted by BITONIC-SORTER, which

has a depth of lg n. It follows by the analog of the zero-one principle given asExercise 27.3-6 that any bitonic sequence of arbitrary numbers can be sorted bythis network.

Exercises

27.3-1How many zero-one bitonic sequences of length n are there?

Recursive Formula for depth D(n):

D(n) =

{0 if n = 1,D(n/2) + 1 if n = 2k .

Henceforth we will alwaysassume that n is a power of 2.

BITONIC-SORTER[n] has depth log n and sorts any zero-one bitonic sequence.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 21

Page 113: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

The Bitonic Sorter27.3 A bitonic sorting network 715

00001011

00001011

00111000

00000111

(b)(a)

bitonic sorted

BITONIC-SORTER[n/2]

HALF-CLEANER[n]

BITONIC-SORTER[n/2]

Figure 27.9 The comparison network BITONIC-SORTER[n], shown here for n = 8. (a) The re-cursive construction: HALF-CLEANER[n] followed by two copies of BITONIC-SORTER[n/2] thatoperate in parallel. (b) The network after unrolling the recursion. Each half-cleaner is shaded. Sam-ple zero-one values are shown on the wires.

The bitonic sorter

By recursively combining half-cleaners, as shown in Figure 27.9, we can builda bitonic sorter, which is a network that sorts bitonic sequences. The first stageof BITONIC-SORTER[n] consists of HALF-CLEANER[n], which, by Lemma 27.3,produces two bitonic sequences of half the size such that every element in thetop half is at least as small as every element in the bottom half. Thus, we cancomplete the sort by using two copies of BITONIC-SORTER[n/2] to sort the twohalves recursively. In Figure 27.9(a), the recursion has been shown explicitly, andin Figure 27.9(b), the recursion has been unrolled to show the progressively smallerhalf-cleaners that make up the remainder of the bitonic sorter. The depth D(n) ofBITONIC-SORTER[n] is given by the recurrence

D(n) =!0 if n = 1 ,D(n/2) + 1 if n = 2k and k ! 1 ,

whose solution is D(n) = lg n.Thus, a zero-one bitonic sequence can be sorted by BITONIC-SORTER, which

has a depth of lg n. It follows by the analog of the zero-one principle given asExercise 27.3-6 that any bitonic sequence of arbitrary numbers can be sorted bythis network.

Exercises

27.3-1How many zero-one bitonic sequences of length n are there?

Recursive Formula for depth D(n):

D(n) =

{0 if n = 1,D(n/2) + 1 if n = 2k .

Henceforth we will alwaysassume that n is a power of 2.

BITONIC-SORTER[n] has depth log n and sorts any zero-one bitonic sequence.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 21

Page 114: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

The Bitonic Sorter27.3 A bitonic sorting network 715

00001011

00001011

00111000

00000111

(b)(a)

bitonic sorted

BITONIC-SORTER[n/2]

HALF-CLEANER[n]

BITONIC-SORTER[n/2]

Figure 27.9 The comparison network BITONIC-SORTER[n], shown here for n = 8. (a) The re-cursive construction: HALF-CLEANER[n] followed by two copies of BITONIC-SORTER[n/2] thatoperate in parallel. (b) The network after unrolling the recursion. Each half-cleaner is shaded. Sam-ple zero-one values are shown on the wires.

The bitonic sorter

By recursively combining half-cleaners, as shown in Figure 27.9, we can builda bitonic sorter, which is a network that sorts bitonic sequences. The first stageof BITONIC-SORTER[n] consists of HALF-CLEANER[n], which, by Lemma 27.3,produces two bitonic sequences of half the size such that every element in thetop half is at least as small as every element in the bottom half. Thus, we cancomplete the sort by using two copies of BITONIC-SORTER[n/2] to sort the twohalves recursively. In Figure 27.9(a), the recursion has been shown explicitly, andin Figure 27.9(b), the recursion has been unrolled to show the progressively smallerhalf-cleaners that make up the remainder of the bitonic sorter. The depth D(n) ofBITONIC-SORTER[n] is given by the recurrence

D(n) =!0 if n = 1 ,D(n/2) + 1 if n = 2k and k ! 1 ,

whose solution is D(n) = lg n.Thus, a zero-one bitonic sequence can be sorted by BITONIC-SORTER, which

has a depth of lg n. It follows by the analog of the zero-one principle given asExercise 27.3-6 that any bitonic sequence of arbitrary numbers can be sorted bythis network.

Exercises

27.3-1How many zero-one bitonic sequences of length n are there?

Recursive Formula for depth D(n):

D(n) =

{0 if n = 1,D(n/2) + 1 if n = 2k .

Henceforth we will alwaysassume that n is a power of 2.

BITONIC-SORTER[n] has depth log n and sorts any zero-one bitonic sequence.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 21

Page 115: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

The Bitonic Sorter27.3 A bitonic sorting network 715

00001011

00001011

00111000

00000111

(b)(a)

bitonic sorted

BITONIC-SORTER[n/2]

HALF-CLEANER[n]

BITONIC-SORTER[n/2]

Figure 27.9 The comparison network BITONIC-SORTER[n], shown here for n = 8. (a) The re-cursive construction: HALF-CLEANER[n] followed by two copies of BITONIC-SORTER[n/2] thatoperate in parallel. (b) The network after unrolling the recursion. Each half-cleaner is shaded. Sam-ple zero-one values are shown on the wires.

The bitonic sorter

By recursively combining half-cleaners, as shown in Figure 27.9, we can builda bitonic sorter, which is a network that sorts bitonic sequences. The first stageof BITONIC-SORTER[n] consists of HALF-CLEANER[n], which, by Lemma 27.3,produces two bitonic sequences of half the size such that every element in thetop half is at least as small as every element in the bottom half. Thus, we cancomplete the sort by using two copies of BITONIC-SORTER[n/2] to sort the twohalves recursively. In Figure 27.9(a), the recursion has been shown explicitly, andin Figure 27.9(b), the recursion has been unrolled to show the progressively smallerhalf-cleaners that make up the remainder of the bitonic sorter. The depth D(n) ofBITONIC-SORTER[n] is given by the recurrence

D(n) =!0 if n = 1 ,D(n/2) + 1 if n = 2k and k ! 1 ,

whose solution is D(n) = lg n.Thus, a zero-one bitonic sequence can be sorted by BITONIC-SORTER, which

has a depth of lg n. It follows by the analog of the zero-one principle given asExercise 27.3-6 that any bitonic sequence of arbitrary numbers can be sorted bythis network.

Exercises

27.3-1How many zero-one bitonic sequences of length n are there?

Recursive Formula for depth D(n):

D(n) =

{0 if n = 1,D(n/2) + 1 if n = 2k .

Henceforth we will alwaysassume that n is a power of 2.

BITONIC-SORTER[n] has depth log n and sorts any zero-one bitonic sequence.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 21

Page 116: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Merging Networks

can merge two sorted input sequences into one sorted outputsequence

will be based on a modification of BITONIC-SORTER[n]

Merging Networks

Basic Idea:

consider two given sequences X = 00000111, Y = 00001111

concatenating X with Y R (the reversal of Y )⇒ 0000011111110000

This sequence is bitonic!

Hence in order to merge the sequences X and Y , it suf-fices to perform a bitonic sort on X concatenated with Y R .

I. Course Intro and Sorting Networks Batcher’s Sorting Network 22

Page 117: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Merging Networks

can merge two sorted input sequences into one sorted outputsequence

will be based on a modification of BITONIC-SORTER[n]

Merging Networks

Basic Idea:

consider two given sequences X = 00000111, Y = 00001111

concatenating X with Y R (the reversal of Y )⇒ 0000011111110000

This sequence is bitonic!

Hence in order to merge the sequences X and Y , it suf-fices to perform a bitonic sort on X concatenated with Y R .

I. Course Intro and Sorting Networks Batcher’s Sorting Network 22

Page 118: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Merging Networks

can merge two sorted input sequences into one sorted outputsequence

will be based on a modification of BITONIC-SORTER[n]

Merging Networks

Basic Idea:

consider two given sequences X = 00000111, Y = 00001111

concatenating X with Y R (the reversal of Y )⇒ 0000011111110000

This sequence is bitonic!

Hence in order to merge the sequences X and Y , it suf-fices to perform a bitonic sort on X concatenated with Y R .

I. Course Intro and Sorting Networks Batcher’s Sorting Network 22

Page 119: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Merging Networks

can merge two sorted input sequences into one sorted outputsequence

will be based on a modification of BITONIC-SORTER[n]

Merging Networks

Basic Idea:

consider two given sequences X = 00000111, Y = 00001111

concatenating X with Y R (the reversal of Y )⇒ 0000011111110000

This sequence is bitonic!

Hence in order to merge the sequences X and Y , it suf-fices to perform a bitonic sort on X concatenated with Y R .

I. Course Intro and Sorting Networks Batcher’s Sorting Network 22

Page 120: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Merging Networks

can merge two sorted input sequences into one sorted outputsequence

will be based on a modification of BITONIC-SORTER[n]

Merging Networks

Basic Idea:

consider two given sequences X = 00000111, Y = 00001111

concatenating X with Y R (the reversal of Y )⇒ 0000011111110000

This sequence is bitonic!

Hence in order to merge the sequences X and Y , it suf-fices to perform a bitonic sort on X concatenated with Y R .

I. Course Intro and Sorting Networks Batcher’s Sorting Network 22

Page 121: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Merging Networks

can merge two sorted input sequences into one sorted outputsequence

will be based on a modification of BITONIC-SORTER[n]

Merging Networks

Basic Idea:

consider two given sequences X = 00000111, Y = 00001111

concatenating X with Y R (the reversal of Y )⇒ 0000011111110000

This sequence is bitonic!

Hence in order to merge the sequences X and Y , it suf-fices to perform a bitonic sort on X concatenated with Y R .

I. Course Intro and Sorting Networks Batcher’s Sorting Network 22

Page 122: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Merging Network (1/2)

Given two sorted sequences 〈a1, a2, . . . , an/2〉 and 〈an/2+1, an/2+2, . . . , an〉

We know it suffices to bitonically sort 〈a1, a2, . . . , an/2, an, an−1, . . . , an/2+1〉Recall: first half-cleaner of BITONIC-SORTER[n] compares i and n/2 + i

⇒ First part of MERGER[n] compares inputs i and n − i for i = 1, 2, . . . , n/2Remaining part is identical to BITONIC-SORTER[n]27.4 A merging network 717

00110001

00001101

a1a2a3a4a5a6a7a8

b1b2b3b4b5b6b7b8

(a)

bitonic

bitonic

sorted

sorted

00111000

00001011

a2a3a4

a5

a6

a7

a8

b1b2b3b4

b5

b6

b7

b8

(b)

bitonic

bitonic

bitonic

a1

Figure 27.10 Comparing the first stage of MERGER[n] with HALF-CLEANER[n], for n = 8.(a) The first stage of MERGER[n] transforms the two monotonic input sequences !a1, a2, . . . , an/2"and !an/2+1, an/2+2, . . . , an" into two bitonic sequences !b1, b2, . . . , bn/2" and !bn/2+1, bn/2+2,. . . , bn". (b) The equivalent operation for HALF-CLEANER[n]. The bitonic input sequence!a1, a2, . . . , an/2#1, an/2, an , an#1, . . . , an/2+2, an/2+1" is transformed into the two bitonic se-quences !b1, b2, . . . , bn/2" and !bn , bn#1, . . . , bn/2+1".

We can construct MERGER[n] by modifying the first half-cleaner of BITONIC-SORTER[n]. The key is to perform the reversal of the second half of the inputsimplicitly. Given two sorted sequences !a1, a2, . . . , an/2" and !an/2+1, an/2+2,. . . , an" to be merged, we want the effect of bitonically sorting the sequence!a1, a2, . . . , an/2, an, an#1, . . . , an/2+1". Since the first half-cleaner of BITONIC-SORTER[n] compares inputs i and n/2 + i , for i = 1, 2, . . . , n/2, we make thefirst stage of the merging network compare inputs i and n # i + 1. Figure 27.10shows the correspondence. The only subtlety is that the order of the outputs fromthe bottom of the first stage of MERGER[n] are reversed compared with the orderof outputs from an ordinary half-cleaner. Since the reversal of a bitonic sequenceis bitonic, however, the top and bottom outputs of the first stage of the mergingnetwork satisfy the properties in Lemma 27.3, and thus the top and bottom can bebitonically sorted in parallel to produce the sorted output of the merging network.The resulting merging network is shown in Figure 27.11. Only the first stage of

MERGER[n] is different from BITONIC-SORTER[n]. Consequently, the depth ofMERGER[n] is lg n, the same as that of BITONIC-SORTER[n].

Exercises

27.4-1Prove an analog of the zero-one principle for merging networks. Specifically, showthat a comparison network that can merge any two monotonically increasing se-

Lemma 27.3 still applies, since the reversal of a bitonic sequence is bitonic.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 23

Page 123: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Merging Network (1/2)

Given two sorted sequences 〈a1, a2, . . . , an/2〉 and 〈an/2+1, an/2+2, . . . , an〉We know it suffices to bitonically sort 〈a1, a2, . . . , an/2, an, an−1, . . . , an/2+1〉

Recall: first half-cleaner of BITONIC-SORTER[n] compares i and n/2 + i⇒ First part of MERGER[n] compares inputs i and n − i for i = 1, 2, . . . , n/2

Remaining part is identical to BITONIC-SORTER[n]27.4 A merging network 717

00110001

00001101

a1a2a3a4a5a6a7a8

b1b2b3b4b5b6b7b8

(a)

bitonic

bitonic

sorted

sorted

00111000

00001011

a2a3a4

a5

a6

a7

a8

b1b2b3b4

b5

b6

b7

b8

(b)

bitonic

bitonic

bitonic

a1

Figure 27.10 Comparing the first stage of MERGER[n] with HALF-CLEANER[n], for n = 8.(a) The first stage of MERGER[n] transforms the two monotonic input sequences !a1, a2, . . . , an/2"and !an/2+1, an/2+2, . . . , an" into two bitonic sequences !b1, b2, . . . , bn/2" and !bn/2+1, bn/2+2,. . . , bn". (b) The equivalent operation for HALF-CLEANER[n]. The bitonic input sequence!a1, a2, . . . , an/2#1, an/2, an , an#1, . . . , an/2+2, an/2+1" is transformed into the two bitonic se-quences !b1, b2, . . . , bn/2" and !bn , bn#1, . . . , bn/2+1".

We can construct MERGER[n] by modifying the first half-cleaner of BITONIC-SORTER[n]. The key is to perform the reversal of the second half of the inputsimplicitly. Given two sorted sequences !a1, a2, . . . , an/2" and !an/2+1, an/2+2,. . . , an" to be merged, we want the effect of bitonically sorting the sequence!a1, a2, . . . , an/2, an, an#1, . . . , an/2+1". Since the first half-cleaner of BITONIC-SORTER[n] compares inputs i and n/2 + i , for i = 1, 2, . . . , n/2, we make thefirst stage of the merging network compare inputs i and n # i + 1. Figure 27.10shows the correspondence. The only subtlety is that the order of the outputs fromthe bottom of the first stage of MERGER[n] are reversed compared with the orderof outputs from an ordinary half-cleaner. Since the reversal of a bitonic sequenceis bitonic, however, the top and bottom outputs of the first stage of the mergingnetwork satisfy the properties in Lemma 27.3, and thus the top and bottom can bebitonically sorted in parallel to produce the sorted output of the merging network.The resulting merging network is shown in Figure 27.11. Only the first stage of

MERGER[n] is different from BITONIC-SORTER[n]. Consequently, the depth ofMERGER[n] is lg n, the same as that of BITONIC-SORTER[n].

Exercises

27.4-1Prove an analog of the zero-one principle for merging networks. Specifically, showthat a comparison network that can merge any two monotonically increasing se-

Lemma 27.3 still applies, since the reversal of a bitonic sequence is bitonic.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 23

Page 124: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Merging Network (1/2)

Given two sorted sequences 〈a1, a2, . . . , an/2〉 and 〈an/2+1, an/2+2, . . . , an〉We know it suffices to bitonically sort 〈a1, a2, . . . , an/2, an, an−1, . . . , an/2+1〉Recall: first half-cleaner of BITONIC-SORTER[n] compares i and n/2 + i

⇒ First part of MERGER[n] compares inputs i and n − i for i = 1, 2, . . . , n/2Remaining part is identical to BITONIC-SORTER[n]27.4 A merging network 717

00110001

00001101

a1a2a3a4a5a6a7a8

b1b2b3b4b5b6b7b8

(a)

bitonic

bitonic

sorted

sorted

00111000

00001011

a2a3a4

a5

a6

a7

a8

b1b2b3b4

b5

b6

b7

b8

(b)

bitonic

bitonic

bitonic

a1

Figure 27.10 Comparing the first stage of MERGER[n] with HALF-CLEANER[n], for n = 8.(a) The first stage of MERGER[n] transforms the two monotonic input sequences !a1, a2, . . . , an/2"and !an/2+1, an/2+2, . . . , an" into two bitonic sequences !b1, b2, . . . , bn/2" and !bn/2+1, bn/2+2,. . . , bn". (b) The equivalent operation for HALF-CLEANER[n]. The bitonic input sequence!a1, a2, . . . , an/2#1, an/2, an , an#1, . . . , an/2+2, an/2+1" is transformed into the two bitonic se-quences !b1, b2, . . . , bn/2" and !bn , bn#1, . . . , bn/2+1".

We can construct MERGER[n] by modifying the first half-cleaner of BITONIC-SORTER[n]. The key is to perform the reversal of the second half of the inputsimplicitly. Given two sorted sequences !a1, a2, . . . , an/2" and !an/2+1, an/2+2,. . . , an" to be merged, we want the effect of bitonically sorting the sequence!a1, a2, . . . , an/2, an, an#1, . . . , an/2+1". Since the first half-cleaner of BITONIC-SORTER[n] compares inputs i and n/2 + i , for i = 1, 2, . . . , n/2, we make thefirst stage of the merging network compare inputs i and n # i + 1. Figure 27.10shows the correspondence. The only subtlety is that the order of the outputs fromthe bottom of the first stage of MERGER[n] are reversed compared with the orderof outputs from an ordinary half-cleaner. Since the reversal of a bitonic sequenceis bitonic, however, the top and bottom outputs of the first stage of the mergingnetwork satisfy the properties in Lemma 27.3, and thus the top and bottom can bebitonically sorted in parallel to produce the sorted output of the merging network.The resulting merging network is shown in Figure 27.11. Only the first stage of

MERGER[n] is different from BITONIC-SORTER[n]. Consequently, the depth ofMERGER[n] is lg n, the same as that of BITONIC-SORTER[n].

Exercises

27.4-1Prove an analog of the zero-one principle for merging networks. Specifically, showthat a comparison network that can merge any two monotonically increasing se-

Lemma 27.3 still applies, since the reversal of a bitonic sequence is bitonic.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 23

Page 125: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Merging Network (1/2)

Given two sorted sequences 〈a1, a2, . . . , an/2〉 and 〈an/2+1, an/2+2, . . . , an〉We know it suffices to bitonically sort 〈a1, a2, . . . , an/2, an, an−1, . . . , an/2+1〉Recall: first half-cleaner of BITONIC-SORTER[n] compares i and n/2 + i

⇒ First part of MERGER[n] compares inputs i and n − i for i = 1, 2, . . . , n/2

Remaining part is identical to BITONIC-SORTER[n]27.4 A merging network 717

00110001

00001101

a1a2a3a4a5a6a7a8

b1b2b3b4b5b6b7b8

(a)

bitonic

bitonic

sorted

sorted

00111000

00001011

a2a3a4

a5

a6

a7

a8

b1b2b3b4

b5

b6

b7

b8

(b)

bitonic

bitonic

bitonic

a1

Figure 27.10 Comparing the first stage of MERGER[n] with HALF-CLEANER[n], for n = 8.(a) The first stage of MERGER[n] transforms the two monotonic input sequences !a1, a2, . . . , an/2"and !an/2+1, an/2+2, . . . , an" into two bitonic sequences !b1, b2, . . . , bn/2" and !bn/2+1, bn/2+2,. . . , bn". (b) The equivalent operation for HALF-CLEANER[n]. The bitonic input sequence!a1, a2, . . . , an/2#1, an/2, an , an#1, . . . , an/2+2, an/2+1" is transformed into the two bitonic se-quences !b1, b2, . . . , bn/2" and !bn , bn#1, . . . , bn/2+1".

We can construct MERGER[n] by modifying the first half-cleaner of BITONIC-SORTER[n]. The key is to perform the reversal of the second half of the inputsimplicitly. Given two sorted sequences !a1, a2, . . . , an/2" and !an/2+1, an/2+2,. . . , an" to be merged, we want the effect of bitonically sorting the sequence!a1, a2, . . . , an/2, an, an#1, . . . , an/2+1". Since the first half-cleaner of BITONIC-SORTER[n] compares inputs i and n/2 + i , for i = 1, 2, . . . , n/2, we make thefirst stage of the merging network compare inputs i and n # i + 1. Figure 27.10shows the correspondence. The only subtlety is that the order of the outputs fromthe bottom of the first stage of MERGER[n] are reversed compared with the orderof outputs from an ordinary half-cleaner. Since the reversal of a bitonic sequenceis bitonic, however, the top and bottom outputs of the first stage of the mergingnetwork satisfy the properties in Lemma 27.3, and thus the top and bottom can bebitonically sorted in parallel to produce the sorted output of the merging network.The resulting merging network is shown in Figure 27.11. Only the first stage of

MERGER[n] is different from BITONIC-SORTER[n]. Consequently, the depth ofMERGER[n] is lg n, the same as that of BITONIC-SORTER[n].

Exercises

27.4-1Prove an analog of the zero-one principle for merging networks. Specifically, showthat a comparison network that can merge any two monotonically increasing se-

Lemma 27.3 still applies, since the reversal of a bitonic sequence is bitonic.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 23

Page 126: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Merging Network (1/2)

Given two sorted sequences 〈a1, a2, . . . , an/2〉 and 〈an/2+1, an/2+2, . . . , an〉We know it suffices to bitonically sort 〈a1, a2, . . . , an/2, an, an−1, . . . , an/2+1〉Recall: first half-cleaner of BITONIC-SORTER[n] compares i and n/2 + i

⇒ First part of MERGER[n] compares inputs i and n − i for i = 1, 2, . . . , n/2

Remaining part is identical to BITONIC-SORTER[n]

27.4 A merging network 717

00110001

00001101

a1a2a3a4a5a6a7a8

b1b2b3b4b5b6b7b8

(a)

bitonic

bitonic

sorted

sorted

00111000

00001011

a2a3a4

a5

a6

a7

a8

b1b2b3b4

b5

b6

b7

b8

(b)

bitonic

bitonic

bitonic

a1

Figure 27.10 Comparing the first stage of MERGER[n] with HALF-CLEANER[n], for n = 8.(a) The first stage of MERGER[n] transforms the two monotonic input sequences !a1, a2, . . . , an/2"and !an/2+1, an/2+2, . . . , an" into two bitonic sequences !b1, b2, . . . , bn/2" and !bn/2+1, bn/2+2,. . . , bn". (b) The equivalent operation for HALF-CLEANER[n]. The bitonic input sequence!a1, a2, . . . , an/2#1, an/2, an , an#1, . . . , an/2+2, an/2+1" is transformed into the two bitonic se-quences !b1, b2, . . . , bn/2" and !bn , bn#1, . . . , bn/2+1".

We can construct MERGER[n] by modifying the first half-cleaner of BITONIC-SORTER[n]. The key is to perform the reversal of the second half of the inputsimplicitly. Given two sorted sequences !a1, a2, . . . , an/2" and !an/2+1, an/2+2,. . . , an" to be merged, we want the effect of bitonically sorting the sequence!a1, a2, . . . , an/2, an, an#1, . . . , an/2+1". Since the first half-cleaner of BITONIC-SORTER[n] compares inputs i and n/2 + i , for i = 1, 2, . . . , n/2, we make thefirst stage of the merging network compare inputs i and n # i + 1. Figure 27.10shows the correspondence. The only subtlety is that the order of the outputs fromthe bottom of the first stage of MERGER[n] are reversed compared with the orderof outputs from an ordinary half-cleaner. Since the reversal of a bitonic sequenceis bitonic, however, the top and bottom outputs of the first stage of the mergingnetwork satisfy the properties in Lemma 27.3, and thus the top and bottom can bebitonically sorted in parallel to produce the sorted output of the merging network.The resulting merging network is shown in Figure 27.11. Only the first stage of

MERGER[n] is different from BITONIC-SORTER[n]. Consequently, the depth ofMERGER[n] is lg n, the same as that of BITONIC-SORTER[n].

Exercises

27.4-1Prove an analog of the zero-one principle for merging networks. Specifically, showthat a comparison network that can merge any two monotonically increasing se-

Lemma 27.3 still applies, since the reversal of a bitonic sequence is bitonic.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 23

Page 127: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Merging Network (1/2)

Given two sorted sequences 〈a1, a2, . . . , an/2〉 and 〈an/2+1, an/2+2, . . . , an〉We know it suffices to bitonically sort 〈a1, a2, . . . , an/2, an, an−1, . . . , an/2+1〉Recall: first half-cleaner of BITONIC-SORTER[n] compares i and n/2 + i

⇒ First part of MERGER[n] compares inputs i and n − i for i = 1, 2, . . . , n/2

Remaining part is identical to BITONIC-SORTER[n]

27.4 A merging network 717

00110001

00001101

a1a2a3a4a5a6a7a8

b1b2b3b4b5b6b7b8

(a)

bitonic

bitonic

sorted

sorted

00111000

00001011

a2a3a4

a5

a6

a7

a8

b1b2b3b4

b5

b6

b7

b8

(b)

bitonic

bitonic

bitonic

a1

Figure 27.10 Comparing the first stage of MERGER[n] with HALF-CLEANER[n], for n = 8.(a) The first stage of MERGER[n] transforms the two monotonic input sequences !a1, a2, . . . , an/2"and !an/2+1, an/2+2, . . . , an" into two bitonic sequences !b1, b2, . . . , bn/2" and !bn/2+1, bn/2+2,. . . , bn". (b) The equivalent operation for HALF-CLEANER[n]. The bitonic input sequence!a1, a2, . . . , an/2#1, an/2, an , an#1, . . . , an/2+2, an/2+1" is transformed into the two bitonic se-quences !b1, b2, . . . , bn/2" and !bn , bn#1, . . . , bn/2+1".

We can construct MERGER[n] by modifying the first half-cleaner of BITONIC-SORTER[n]. The key is to perform the reversal of the second half of the inputsimplicitly. Given two sorted sequences !a1, a2, . . . , an/2" and !an/2+1, an/2+2,. . . , an" to be merged, we want the effect of bitonically sorting the sequence!a1, a2, . . . , an/2, an, an#1, . . . , an/2+1". Since the first half-cleaner of BITONIC-SORTER[n] compares inputs i and n/2 + i , for i = 1, 2, . . . , n/2, we make thefirst stage of the merging network compare inputs i and n # i + 1. Figure 27.10shows the correspondence. The only subtlety is that the order of the outputs fromthe bottom of the first stage of MERGER[n] are reversed compared with the orderof outputs from an ordinary half-cleaner. Since the reversal of a bitonic sequenceis bitonic, however, the top and bottom outputs of the first stage of the mergingnetwork satisfy the properties in Lemma 27.3, and thus the top and bottom can bebitonically sorted in parallel to produce the sorted output of the merging network.The resulting merging network is shown in Figure 27.11. Only the first stage of

MERGER[n] is different from BITONIC-SORTER[n]. Consequently, the depth ofMERGER[n] is lg n, the same as that of BITONIC-SORTER[n].

Exercises

27.4-1Prove an analog of the zero-one principle for merging networks. Specifically, showthat a comparison network that can merge any two monotonically increasing se-

Lemma 27.3 still applies, since the reversal of a bitonic sequence is bitonic.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 23

Page 128: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Merging Network (1/2)

Given two sorted sequences 〈a1, a2, . . . , an/2〉 and 〈an/2+1, an/2+2, . . . , an〉We know it suffices to bitonically sort 〈a1, a2, . . . , an/2, an, an−1, . . . , an/2+1〉Recall: first half-cleaner of BITONIC-SORTER[n] compares i and n/2 + i

⇒ First part of MERGER[n] compares inputs i and n − i for i = 1, 2, . . . , n/2

Remaining part is identical to BITONIC-SORTER[n]

27.4 A merging network 717

00110001

00001101

a1a2a3a4a5a6a7a8

b1b2b3b4b5b6b7b8

(a)

bitonic

bitonic

sorted

sorted

00111000

00001011

a2a3a4

a5

a6

a7

a8

b1b2b3b4

b5

b6

b7

b8

(b)

bitonic

bitonic

bitonic

a1

Figure 27.10 Comparing the first stage of MERGER[n] with HALF-CLEANER[n], for n = 8.(a) The first stage of MERGER[n] transforms the two monotonic input sequences !a1, a2, . . . , an/2"and !an/2+1, an/2+2, . . . , an" into two bitonic sequences !b1, b2, . . . , bn/2" and !bn/2+1, bn/2+2,. . . , bn". (b) The equivalent operation for HALF-CLEANER[n]. The bitonic input sequence!a1, a2, . . . , an/2#1, an/2, an , an#1, . . . , an/2+2, an/2+1" is transformed into the two bitonic se-quences !b1, b2, . . . , bn/2" and !bn , bn#1, . . . , bn/2+1".

We can construct MERGER[n] by modifying the first half-cleaner of BITONIC-SORTER[n]. The key is to perform the reversal of the second half of the inputsimplicitly. Given two sorted sequences !a1, a2, . . . , an/2" and !an/2+1, an/2+2,. . . , an" to be merged, we want the effect of bitonically sorting the sequence!a1, a2, . . . , an/2, an, an#1, . . . , an/2+1". Since the first half-cleaner of BITONIC-SORTER[n] compares inputs i and n/2 + i , for i = 1, 2, . . . , n/2, we make thefirst stage of the merging network compare inputs i and n # i + 1. Figure 27.10shows the correspondence. The only subtlety is that the order of the outputs fromthe bottom of the first stage of MERGER[n] are reversed compared with the orderof outputs from an ordinary half-cleaner. Since the reversal of a bitonic sequenceis bitonic, however, the top and bottom outputs of the first stage of the mergingnetwork satisfy the properties in Lemma 27.3, and thus the top and bottom can bebitonically sorted in parallel to produce the sorted output of the merging network.The resulting merging network is shown in Figure 27.11. Only the first stage of

MERGER[n] is different from BITONIC-SORTER[n]. Consequently, the depth ofMERGER[n] is lg n, the same as that of BITONIC-SORTER[n].

Exercises

27.4-1Prove an analog of the zero-one principle for merging networks. Specifically, showthat a comparison network that can merge any two monotonically increasing se-

Lemma 27.3 still applies, since the reversal of a bitonic sequence is bitonic.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 23

Page 129: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Merging Network (1/2)

Given two sorted sequences 〈a1, a2, . . . , an/2〉 and 〈an/2+1, an/2+2, . . . , an〉We know it suffices to bitonically sort 〈a1, a2, . . . , an/2, an, an−1, . . . , an/2+1〉Recall: first half-cleaner of BITONIC-SORTER[n] compares i and n/2 + i

⇒ First part of MERGER[n] compares inputs i and n − i for i = 1, 2, . . . , n/2Remaining part is identical to BITONIC-SORTER[n]27.4 A merging network 717

00110001

00001101

a1a2a3a4a5a6a7a8

b1b2b3b4b5b6b7b8

(a)

bitonic

bitonic

sorted

sorted

00111000

00001011

a2a3a4

a5

a6

a7

a8

b1b2b3b4

b5

b6

b7

b8

(b)

bitonic

bitonic

bitonic

a1

Figure 27.10 Comparing the first stage of MERGER[n] with HALF-CLEANER[n], for n = 8.(a) The first stage of MERGER[n] transforms the two monotonic input sequences !a1, a2, . . . , an/2"and !an/2+1, an/2+2, . . . , an" into two bitonic sequences !b1, b2, . . . , bn/2" and !bn/2+1, bn/2+2,. . . , bn". (b) The equivalent operation for HALF-CLEANER[n]. The bitonic input sequence!a1, a2, . . . , an/2#1, an/2, an , an#1, . . . , an/2+2, an/2+1" is transformed into the two bitonic se-quences !b1, b2, . . . , bn/2" and !bn , bn#1, . . . , bn/2+1".

We can construct MERGER[n] by modifying the first half-cleaner of BITONIC-SORTER[n]. The key is to perform the reversal of the second half of the inputsimplicitly. Given two sorted sequences !a1, a2, . . . , an/2" and !an/2+1, an/2+2,. . . , an" to be merged, we want the effect of bitonically sorting the sequence!a1, a2, . . . , an/2, an, an#1, . . . , an/2+1". Since the first half-cleaner of BITONIC-SORTER[n] compares inputs i and n/2 + i , for i = 1, 2, . . . , n/2, we make thefirst stage of the merging network compare inputs i and n # i + 1. Figure 27.10shows the correspondence. The only subtlety is that the order of the outputs fromthe bottom of the first stage of MERGER[n] are reversed compared with the orderof outputs from an ordinary half-cleaner. Since the reversal of a bitonic sequenceis bitonic, however, the top and bottom outputs of the first stage of the mergingnetwork satisfy the properties in Lemma 27.3, and thus the top and bottom can bebitonically sorted in parallel to produce the sorted output of the merging network.The resulting merging network is shown in Figure 27.11. Only the first stage of

MERGER[n] is different from BITONIC-SORTER[n]. Consequently, the depth ofMERGER[n] is lg n, the same as that of BITONIC-SORTER[n].

Exercises

27.4-1Prove an analog of the zero-one principle for merging networks. Specifically, showthat a comparison network that can merge any two monotonically increasing se-

Lemma 27.3 still applies, since the reversal of a bitonic sequence is bitonic.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 23

Page 130: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Merging Network (2/2)

718 Chapter 27 Sorting Networks

00101111

00101111

00110111

00011111

(b)(a)

sorted

sorted

sorted

BITONIC-SORTER[n/2]

BITONIC-SORTER[n/2]

Figure 27.11 A network that merges two sorted input sequences into one sorted output sequence.The network MERGER[n] can be viewed as BITONIC-SORTER[n]with the first half-cleaner altered tocompare inputs i and n! i+1 for i = 1, 2, . . . , n/2. Here, n = 8. (a) The network decomposed intothe first stage followed by two parallel copies of BITONIC-SORTER[n/2]. (b) The same network withthe recursion unrolled. Sample zero-one values are shown on the wires, and the stages are shaded.

quences of 0’s and 1’s can merge any two monotonically increasing sequences ofarbitrary numbers.

27.4-2How many different zero-one input sequences must be applied to the input of acomparison network to verify that it is a merging network?

27.4-3Show that any network that can merge 1 item with n ! 1 sorted items to produce asorted sequence of length n must have depth at least lg n.

27.4-4 !Consider a merging network with inputs a1, a2, . . . , an , for n an exact power of 2,in which the two monotonic sequences to be merged are "a1, a3, . . . , an!1# and"a2, a4, . . . , an#. Prove that the number of comparators in this kind of mergingnetwork is "(n lg n). Why is this an interesting lower bound? (Hint: Partition thecomparators into three sets.)

27.4-5 !Prove that any merging network, regardless of the order of inputs, requires"(n lg n) comparators.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 24

Page 131: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Sorting Network

1. BITONIC-SORTER[n]sorts any bitonic sequencedepth log n

2. MERGER[n]

merges two sorted input sequencesdepth log n

Main Components

SORTER[n] is defined recursively:If n = 2k , use two copies of SORTER[n/2] tosort two subsequences of length n/2 each.Then merge them using MERGER[n].If n = 1, network consists of a single wire.

Batcher’s Sorting Network

can be seen as a parallel version of merge sort

27.3 A bitonic sorting network 715

00001011

00001011

00111000

00000111

(b)(a)

bitonic sorted

BITONIC-SORTER[n/2]

HALF-CLEANER[n]

BITONIC-SORTER[n/2]

Figure 27.9 The comparison network BITONIC-SORTER[n], shown here for n = 8. (a) The re-cursive construction: HALF-CLEANER[n] followed by two copies of BITONIC-SORTER[n/2] thatoperate in parallel. (b) The network after unrolling the recursion. Each half-cleaner is shaded. Sam-ple zero-one values are shown on the wires.

The bitonic sorter

By recursively combining half-cleaners, as shown in Figure 27.9, we can builda bitonic sorter, which is a network that sorts bitonic sequences. The first stageof BITONIC-SORTER[n] consists of HALF-CLEANER[n], which, by Lemma 27.3,produces two bitonic sequences of half the size such that every element in thetop half is at least as small as every element in the bottom half. Thus, we cancomplete the sort by using two copies of BITONIC-SORTER[n/2] to sort the twohalves recursively. In Figure 27.9(a), the recursion has been shown explicitly, andin Figure 27.9(b), the recursion has been unrolled to show the progressively smallerhalf-cleaners that make up the remainder of the bitonic sorter. The depth D(n) ofBITONIC-SORTER[n] is given by the recurrence

D(n) =!0 if n = 1 ,D(n/2) + 1 if n = 2k and k ! 1 ,

whose solution is D(n) = lg n.Thus, a zero-one bitonic sequence can be sorted by BITONIC-SORTER, which

has a depth of lg n. It follows by the analog of the zero-one principle given asExercise 27.3-6 that any bitonic sequence of arbitrary numbers can be sorted bythis network.

Exercises

27.3-1How many zero-one bitonic sequences of length n are there?

718 Chapter 27 Sorting Networks

00101111

00101111

00110111

00011111

(b)(a)

sorted

sorted

sorted

BITONIC-SORTER[n/2]

BITONIC-SORTER[n/2]

Figure 27.11 A network that merges two sorted input sequences into one sorted output sequence.The network MERGER[n] can be viewed as BITONIC-SORTER[n]with the first half-cleaner altered tocompare inputs i and n! i+1 for i = 1, 2, . . . , n/2. Here, n = 8. (a) The network decomposed intothe first stage followed by two parallel copies of BITONIC-SORTER[n/2]. (b) The same network withthe recursion unrolled. Sample zero-one values are shown on the wires, and the stages are shaded.

quences of 0’s and 1’s can merge any two monotonically increasing sequences ofarbitrary numbers.

27.4-2How many different zero-one input sequences must be applied to the input of acomparison network to verify that it is a merging network?

27.4-3Show that any network that can merge 1 item with n ! 1 sorted items to produce asorted sequence of length n must have depth at least lg n.

27.4-4 !Consider a merging network with inputs a1, a2, . . . , an , for n an exact power of 2,in which the two monotonic sequences to be merged are "a1, a3, . . . , an!1# and"a2, a4, . . . , an#. Prove that the number of comparators in this kind of mergingnetwork is "(n lg n). Why is this an interesting lower bound? (Hint: Partition thecomparators into three sets.)

27.4-5 !Prove that any merging network, regardless of the order of inputs, requires"(n lg n) comparators.

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

1.

2.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 25

Page 132: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Sorting Network

1. BITONIC-SORTER[n]sorts any bitonic sequencedepth log n

2. MERGER[n]merges two sorted input sequencesdepth log n

Main Components

SORTER[n] is defined recursively:If n = 2k , use two copies of SORTER[n/2] tosort two subsequences of length n/2 each.Then merge them using MERGER[n].If n = 1, network consists of a single wire.

Batcher’s Sorting Network

can be seen as a parallel version of merge sort

27.3 A bitonic sorting network 715

00001011

00001011

00111000

00000111

(b)(a)

bitonic sorted

BITONIC-SORTER[n/2]

HALF-CLEANER[n]

BITONIC-SORTER[n/2]

Figure 27.9 The comparison network BITONIC-SORTER[n], shown here for n = 8. (a) The re-cursive construction: HALF-CLEANER[n] followed by two copies of BITONIC-SORTER[n/2] thatoperate in parallel. (b) The network after unrolling the recursion. Each half-cleaner is shaded. Sam-ple zero-one values are shown on the wires.

The bitonic sorter

By recursively combining half-cleaners, as shown in Figure 27.9, we can builda bitonic sorter, which is a network that sorts bitonic sequences. The first stageof BITONIC-SORTER[n] consists of HALF-CLEANER[n], which, by Lemma 27.3,produces two bitonic sequences of half the size such that every element in thetop half is at least as small as every element in the bottom half. Thus, we cancomplete the sort by using two copies of BITONIC-SORTER[n/2] to sort the twohalves recursively. In Figure 27.9(a), the recursion has been shown explicitly, andin Figure 27.9(b), the recursion has been unrolled to show the progressively smallerhalf-cleaners that make up the remainder of the bitonic sorter. The depth D(n) ofBITONIC-SORTER[n] is given by the recurrence

D(n) =!0 if n = 1 ,D(n/2) + 1 if n = 2k and k ! 1 ,

whose solution is D(n) = lg n.Thus, a zero-one bitonic sequence can be sorted by BITONIC-SORTER, which

has a depth of lg n. It follows by the analog of the zero-one principle given asExercise 27.3-6 that any bitonic sequence of arbitrary numbers can be sorted bythis network.

Exercises

27.3-1How many zero-one bitonic sequences of length n are there?

718 Chapter 27 Sorting Networks

00101111

00101111

00110111

00011111

(b)(a)

sorted

sorted

sorted

BITONIC-SORTER[n/2]

BITONIC-SORTER[n/2]

Figure 27.11 A network that merges two sorted input sequences into one sorted output sequence.The network MERGER[n] can be viewed as BITONIC-SORTER[n]with the first half-cleaner altered tocompare inputs i and n! i+1 for i = 1, 2, . . . , n/2. Here, n = 8. (a) The network decomposed intothe first stage followed by two parallel copies of BITONIC-SORTER[n/2]. (b) The same network withthe recursion unrolled. Sample zero-one values are shown on the wires, and the stages are shaded.

quences of 0’s and 1’s can merge any two monotonically increasing sequences ofarbitrary numbers.

27.4-2How many different zero-one input sequences must be applied to the input of acomparison network to verify that it is a merging network?

27.4-3Show that any network that can merge 1 item with n ! 1 sorted items to produce asorted sequence of length n must have depth at least lg n.

27.4-4 !Consider a merging network with inputs a1, a2, . . . , an , for n an exact power of 2,in which the two monotonic sequences to be merged are "a1, a3, . . . , an!1# and"a2, a4, . . . , an#. Prove that the number of comparators in this kind of mergingnetwork is "(n lg n). Why is this an interesting lower bound? (Hint: Partition thecomparators into three sets.)

27.4-5 !Prove that any merging network, regardless of the order of inputs, requires"(n lg n) comparators.

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

1.

2.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 25

Page 133: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Sorting Network

1. BITONIC-SORTER[n]sorts any bitonic sequencedepth log n

2. MERGER[n]merges two sorted input sequencesdepth log n

Main Components

SORTER[n] is defined recursively:If n = 2k , use two copies of SORTER[n/2] tosort two subsequences of length n/2 each.Then merge them using MERGER[n].If n = 1, network consists of a single wire.

Batcher’s Sorting Network

can be seen as a parallel version of merge sort

27.3 A bitonic sorting network 715

00001011

00001011

00111000

00000111

(b)(a)

bitonic sorted

BITONIC-SORTER[n/2]

HALF-CLEANER[n]

BITONIC-SORTER[n/2]

Figure 27.9 The comparison network BITONIC-SORTER[n], shown here for n = 8. (a) The re-cursive construction: HALF-CLEANER[n] followed by two copies of BITONIC-SORTER[n/2] thatoperate in parallel. (b) The network after unrolling the recursion. Each half-cleaner is shaded. Sam-ple zero-one values are shown on the wires.

The bitonic sorter

By recursively combining half-cleaners, as shown in Figure 27.9, we can builda bitonic sorter, which is a network that sorts bitonic sequences. The first stageof BITONIC-SORTER[n] consists of HALF-CLEANER[n], which, by Lemma 27.3,produces two bitonic sequences of half the size such that every element in thetop half is at least as small as every element in the bottom half. Thus, we cancomplete the sort by using two copies of BITONIC-SORTER[n/2] to sort the twohalves recursively. In Figure 27.9(a), the recursion has been shown explicitly, andin Figure 27.9(b), the recursion has been unrolled to show the progressively smallerhalf-cleaners that make up the remainder of the bitonic sorter. The depth D(n) ofBITONIC-SORTER[n] is given by the recurrence

D(n) =!0 if n = 1 ,D(n/2) + 1 if n = 2k and k ! 1 ,

whose solution is D(n) = lg n.Thus, a zero-one bitonic sequence can be sorted by BITONIC-SORTER, which

has a depth of lg n. It follows by the analog of the zero-one principle given asExercise 27.3-6 that any bitonic sequence of arbitrary numbers can be sorted bythis network.

Exercises

27.3-1How many zero-one bitonic sequences of length n are there?

718 Chapter 27 Sorting Networks

00101111

00101111

00110111

00011111

(b)(a)

sorted

sorted

sorted

BITONIC-SORTER[n/2]

BITONIC-SORTER[n/2]

Figure 27.11 A network that merges two sorted input sequences into one sorted output sequence.The network MERGER[n] can be viewed as BITONIC-SORTER[n]with the first half-cleaner altered tocompare inputs i and n! i+1 for i = 1, 2, . . . , n/2. Here, n = 8. (a) The network decomposed intothe first stage followed by two parallel copies of BITONIC-SORTER[n/2]. (b) The same network withthe recursion unrolled. Sample zero-one values are shown on the wires, and the stages are shaded.

quences of 0’s and 1’s can merge any two monotonically increasing sequences ofarbitrary numbers.

27.4-2How many different zero-one input sequences must be applied to the input of acomparison network to verify that it is a merging network?

27.4-3Show that any network that can merge 1 item with n ! 1 sorted items to produce asorted sequence of length n must have depth at least lg n.

27.4-4 !Consider a merging network with inputs a1, a2, . . . , an , for n an exact power of 2,in which the two monotonic sequences to be merged are "a1, a3, . . . , an!1# and"a2, a4, . . . , an#. Prove that the number of comparators in this kind of mergingnetwork is "(n lg n). Why is this an interesting lower bound? (Hint: Partition thecomparators into three sets.)

27.4-5 !Prove that any merging network, regardless of the order of inputs, requires"(n lg n) comparators.

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

1.

2.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 25

Page 134: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Construction of a Sorting Network

1. BITONIC-SORTER[n]sorts any bitonic sequencedepth log n

2. MERGER[n]merges two sorted input sequencesdepth log n

Main Components

SORTER[n] is defined recursively:If n = 2k , use two copies of SORTER[n/2] tosort two subsequences of length n/2 each.Then merge them using MERGER[n].If n = 1, network consists of a single wire.

Batcher’s Sorting Network

can be seen as a parallel version of merge sort

27.3 A bitonic sorting network 715

00001011

00001011

00111000

00000111

(b)(a)

bitonic sorted

BITONIC-SORTER[n/2]

HALF-CLEANER[n]

BITONIC-SORTER[n/2]

Figure 27.9 The comparison network BITONIC-SORTER[n], shown here for n = 8. (a) The re-cursive construction: HALF-CLEANER[n] followed by two copies of BITONIC-SORTER[n/2] thatoperate in parallel. (b) The network after unrolling the recursion. Each half-cleaner is shaded. Sam-ple zero-one values are shown on the wires.

The bitonic sorter

By recursively combining half-cleaners, as shown in Figure 27.9, we can builda bitonic sorter, which is a network that sorts bitonic sequences. The first stageof BITONIC-SORTER[n] consists of HALF-CLEANER[n], which, by Lemma 27.3,produces two bitonic sequences of half the size such that every element in thetop half is at least as small as every element in the bottom half. Thus, we cancomplete the sort by using two copies of BITONIC-SORTER[n/2] to sort the twohalves recursively. In Figure 27.9(a), the recursion has been shown explicitly, andin Figure 27.9(b), the recursion has been unrolled to show the progressively smallerhalf-cleaners that make up the remainder of the bitonic sorter. The depth D(n) ofBITONIC-SORTER[n] is given by the recurrence

D(n) =!0 if n = 1 ,D(n/2) + 1 if n = 2k and k ! 1 ,

whose solution is D(n) = lg n.Thus, a zero-one bitonic sequence can be sorted by BITONIC-SORTER, which

has a depth of lg n. It follows by the analog of the zero-one principle given asExercise 27.3-6 that any bitonic sequence of arbitrary numbers can be sorted bythis network.

Exercises

27.3-1How many zero-one bitonic sequences of length n are there?

718 Chapter 27 Sorting Networks

00101111

00101111

00110111

00011111

(b)(a)

sorted

sorted

sorted

BITONIC-SORTER[n/2]

BITONIC-SORTER[n/2]

Figure 27.11 A network that merges two sorted input sequences into one sorted output sequence.The network MERGER[n] can be viewed as BITONIC-SORTER[n]with the first half-cleaner altered tocompare inputs i and n! i+1 for i = 1, 2, . . . , n/2. Here, n = 8. (a) The network decomposed intothe first stage followed by two parallel copies of BITONIC-SORTER[n/2]. (b) The same network withthe recursion unrolled. Sample zero-one values are shown on the wires, and the stages are shaded.

quences of 0’s and 1’s can merge any two monotonically increasing sequences ofarbitrary numbers.

27.4-2How many different zero-one input sequences must be applied to the input of acomparison network to verify that it is a merging network?

27.4-3Show that any network that can merge 1 item with n ! 1 sorted items to produce asorted sequence of length n must have depth at least lg n.

27.4-4 !Consider a merging network with inputs a1, a2, . . . , an , for n an exact power of 2,in which the two monotonic sequences to be merged are "a1, a3, . . . , an!1# and"a2, a4, . . . , an#. Prove that the number of comparators in this kind of mergingnetwork is "(n lg n). Why is this an interesting lower bound? (Hint: Partition thecomparators into three sets.)

27.4-5 !Prove that any merging network, regardless of the order of inputs, requires"(n lg n) comparators.

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

1.

2.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 25

Page 135: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Unrolling the Recursion (Figure 27.12)720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

Recursion for D(n):

D(n) =

{0 if n = 1,D(n/2) + log n if n = 2k .

Solution: D(n) = Θ(log2 n).

SORTER[n] has depth Θ(log2 n) and sorts any input.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 26

Page 136: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Unrolling the Recursion (Figure 27.12)720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

Recursion for D(n):

D(n) =

{0 if n = 1,D(n/2) + log n if n = 2k .

Solution: D(n) = Θ(log2 n).

SORTER[n] has depth Θ(log2 n) and sorts any input.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 26

Page 137: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Unrolling the Recursion (Figure 27.12)720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

Recursion for D(n):

D(n) =

{0 if n = 1,D(n/2) + log n if n = 2k .

Solution: D(n) = Θ(log2 n).

SORTER[n] has depth Θ(log2 n) and sorts any input.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 26

Page 138: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Unrolling the Recursion (Figure 27.12)720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

Recursion for D(n):

D(n) =

{0 if n = 1,D(n/2) + log n if n = 2k .

Solution: D(n) = Θ(log2 n).

SORTER[n] has depth Θ(log2 n) and sorts any input.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 26

Page 139: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Unrolling the Recursion (Figure 27.12)720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

Recursion for D(n):

D(n) =

{0 if n = 1,D(n/2) + log n if n = 2k .

Solution: D(n) = Θ(log2 n).

SORTER[n] has depth Θ(log2 n) and sorts any input.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 26

Page 140: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Unrolling the Recursion (Figure 27.12)720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

720 Chapter 27 Sorting Networks

10101000

00000111

01010100

00110001

1 2 2 3 4 4 4 4 5 5 6depth(c)

(a) (b)

SORTER[n/2]

MERGER[n] MERGER[8]

MERGER[2]

SORTER[n/2]

MERGER[2]

MERGER[2]

MERGER[2]

MERGER[4]

MERGER[4]

Figure 27.12 The sorting network SORTER[n] constructed by recursively combining merging net-works. (a) The recursive construction. (b)Unrolling the recursion. (c) Replacing the MERGER boxeswith the actual merging networks. The depth of each comparator is indicated, and sample zero-onevalues are shown on the wires.

27.5-2Show that the depth of SORTER[n] is exactly (lg n)(lg n + 1)/2.

27.5-3Suppose that we have 2n elements !a1,a2, . . . ,a2n" and wish to partition them intothe n smallest and the n largest. Prove that we can do this in constant additionaldepth after separately sorting !a1, a2, . . . , an" and !an+1, an+2, . . . , a2n".

27.5-4 !Let S(k) be the depth of a sorting network with k inputs, and let M(k) be thedepth of a merging network with 2k inputs. Suppose that we have a sequence of nnumbers to be sorted and we know that every number is within k positions of itscorrect position in the sorted order. Show that we can sort the n numbers in depthS(k) + 2M(k).

Recursion for D(n):

D(n) =

{0 if n = 1,D(n/2) + log n if n = 2k .

Solution: D(n) = Θ(log2 n).

SORTER[n] has depth Θ(log2 n) and sorts any input.

I. Course Intro and Sorting Networks Batcher’s Sorting Network 26

Page 141: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

A Glimpse at the AKS Network

There exists a sorting network with depth O(log n).Ajtai, Komlós, Szemerédi (1983)

Quite elaborate construction, and involves huges constants.

A perfect halver is a comparison network that, given any input, places then/2 smaller keys in b1, . . . , bn/2 and the n/2 larger keys in bn/2+1, . . . , bn.

Perfect Halver

Perfect halver of depth log2 n exist yields sorting networks of depth Θ((log n)2).

An (n, ε)-approximate halver, ε < 1, is a comparison network that forevery k = 1, 2, . . . , n/2 places at most εk of its k smallest keys inbn/2+1, . . . , bn and at most εk of its k largest keys in b1, . . . , bn/2.

Approximate Halver

We will prove that such networks can be constructed in constant depth!

I. Course Intro and Sorting Networks Batcher’s Sorting Network 27

Page 142: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

A Glimpse at the AKS Network

There exists a sorting network with depth O(log n).Ajtai, Komlós, Szemerédi (1983)

Quite elaborate construction, and involves huges constants.

A perfect halver is a comparison network that, given any input, places then/2 smaller keys in b1, . . . , bn/2 and the n/2 larger keys in bn/2+1, . . . , bn.

Perfect Halver

Perfect halver of depth log2 n exist yields sorting networks of depth Θ((log n)2).

An (n, ε)-approximate halver, ε < 1, is a comparison network that forevery k = 1, 2, . . . , n/2 places at most εk of its k smallest keys inbn/2+1, . . . , bn and at most εk of its k largest keys in b1, . . . , bn/2.

Approximate Halver

We will prove that such networks can be constructed in constant depth!

I. Course Intro and Sorting Networks Batcher’s Sorting Network 27

Page 143: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

A Glimpse at the AKS Network

There exists a sorting network with depth O(log n).Ajtai, Komlós, Szemerédi (1983)

Quite elaborate construction, and involves huges constants.

A perfect halver is a comparison network that, given any input, places then/2 smaller keys in b1, . . . , bn/2 and the n/2 larger keys in bn/2+1, . . . , bn.

Perfect Halver

Perfect halver of depth log2 n exist yields sorting networks of depth Θ((log n)2).

An (n, ε)-approximate halver, ε < 1, is a comparison network that forevery k = 1, 2, . . . , n/2 places at most εk of its k smallest keys inbn/2+1, . . . , bn and at most εk of its k largest keys in b1, . . . , bn/2.

Approximate Halver

We will prove that such networks can be constructed in constant depth!

I. Course Intro and Sorting Networks Batcher’s Sorting Network 27

Page 144: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

A Glimpse at the AKS Network

There exists a sorting network with depth O(log n).Ajtai, Komlós, Szemerédi (1983)

Quite elaborate construction, and involves huges constants.

A perfect halver is a comparison network that, given any input, places then/2 smaller keys in b1, . . . , bn/2 and the n/2 larger keys in bn/2+1, . . . , bn.

Perfect Halver

Perfect halver of depth log2 n exist yields sorting networks of depth Θ((log n)2).

An (n, ε)-approximate halver, ε < 1, is a comparison network that forevery k = 1, 2, . . . , n/2 places at most εk of its k smallest keys inbn/2+1, . . . , bn and at most εk of its k largest keys in b1, . . . , bn/2.

Approximate Halver

We will prove that such networks can be constructed in constant depth!

I. Course Intro and Sorting Networks Batcher’s Sorting Network 27

Page 145: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

A Glimpse at the AKS Network

There exists a sorting network with depth O(log n).Ajtai, Komlós, Szemerédi (1983)

Quite elaborate construction, and involves huges constants.

A perfect halver is a comparison network that, given any input, places then/2 smaller keys in b1, . . . , bn/2 and the n/2 larger keys in bn/2+1, . . . , bn.

Perfect Halver

Perfect halver of depth log2 n exist yields sorting networks of depth Θ((log n)2).

An (n, ε)-approximate halver, ε < 1, is a comparison network that forevery k = 1, 2, . . . , n/2 places at most εk of its k smallest keys inbn/2+1, . . . , bn and at most εk of its k largest keys in b1, . . . , bn/2.

Approximate Halver

We will prove that such networks can be constructed in constant depth!

I. Course Intro and Sorting Networks Batcher’s Sorting Network 27

Page 146: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

A Glimpse at the AKS Network

There exists a sorting network with depth O(log n).Ajtai, Komlós, Szemerédi (1983)

Quite elaborate construction, and involves huges constants.

A perfect halver is a comparison network that, given any input, places then/2 smaller keys in b1, . . . , bn/2 and the n/2 larger keys in bn/2+1, . . . , bn.

Perfect Halver

Perfect halver of depth log2 n exist yields sorting networks of depth Θ((log n)2).

An (n, ε)-approximate halver, ε < 1, is a comparison network that forevery k = 1, 2, . . . , n/2 places at most εk of its k smallest keys inbn/2+1, . . . , bn and at most εk of its k largest keys in b1, . . . , bn/2.

Approximate Halver

We will prove that such networks can be constructed in constant depth!

I. Course Intro and Sorting Networks Batcher’s Sorting Network 27

Page 147: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Expander Graphs

A bipartite (n, d , µ)-expander is a graph with:

G has n vertices (n/2 on each side)

the edge-set is union of d perfect matchings

For every subset S ⊆ V being in one part,

|N(S)| > min{µ · |S|, n/2− |S|}

Expander Graphs

L R

Specific definition tailored for sortingnetwork - many other variants exist!

Expander Graphs:probabilistic construction “easy”: take d (disjoint) random matchings

explicit construction is a deep mathematical problem with ties tonumber theory, group theory, combinatorics etc.

many applications in networking, complexity theory and coding theory

I. Course Intro and Sorting Networks Batcher’s Sorting Network 28

Page 148: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Expander Graphs

A bipartite (n, d , µ)-expander is a graph with:

G has n vertices (n/2 on each side)

the edge-set is union of d perfect matchings

For every subset S ⊆ V being in one part,

|N(S)| > min{µ · |S|, n/2− |S|}

Expander Graphs

L R

Specific definition tailored for sortingnetwork - many other variants exist!

Expander Graphs:probabilistic construction “easy”: take d (disjoint) random matchings

explicit construction is a deep mathematical problem with ties tonumber theory, group theory, combinatorics etc.

many applications in networking, complexity theory and coding theory

I. Course Intro and Sorting Networks Batcher’s Sorting Network 28

Page 149: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Expander Graphs

A bipartite (n, d , µ)-expander is a graph with:

G has n vertices (n/2 on each side)

the edge-set is union of d perfect matchings

For every subset S ⊆ V being in one part,

|N(S)| > min{µ · |S|, n/2− |S|}

Expander Graphs

L R

Specific definition tailored for sortingnetwork - many other variants exist!

Expander Graphs:probabilistic construction “easy”: take d (disjoint) random matchings

explicit construction is a deep mathematical problem with ties tonumber theory, group theory, combinatorics etc.

many applications in networking, complexity theory and coding theory

I. Course Intro and Sorting Networks Batcher’s Sorting Network 28

Page 150: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Expander Graphs

A bipartite (n, d , µ)-expander is a graph with:

G has n vertices (n/2 on each side)

the edge-set is union of d perfect matchings

For every subset S ⊆ V being in one part,

|N(S)| > min{µ · |S|, n/2− |S|}

Expander Graphs

L R

Specific definition tailored for sortingnetwork - many other variants exist!

Expander Graphs:probabilistic construction “easy”: take d (disjoint) random matchings

explicit construction is a deep mathematical problem with ties tonumber theory, group theory, combinatorics etc.

many applications in networking, complexity theory and coding theory

I. Course Intro and Sorting Networks Batcher’s Sorting Network 28

Page 151: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Expander Graphs

A bipartite (n, d , µ)-expander is a graph with:

G has n vertices (n/2 on each side)

the edge-set is union of d perfect matchings

For every subset S ⊆ V being in one part,

|N(S)| > min{µ · |S|, n/2− |S|}

Expander Graphs

L RSpecific definition tailored for sortingnetwork - many other variants exist!

Expander Graphs:probabilistic construction “easy”: take d (disjoint) random matchings

explicit construction is a deep mathematical problem with ties tonumber theory, group theory, combinatorics etc.

many applications in networking, complexity theory and coding theory

I. Course Intro and Sorting Networks Batcher’s Sorting Network 28

Page 152: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Expander Graphs

A bipartite (n, d , µ)-expander is a graph with:

G has n vertices (n/2 on each side)

the edge-set is union of d perfect matchings

For every subset S ⊆ V being in one part,

|N(S)| > min{µ · |S|, n/2− |S|}

Expander Graphs

L R

Specific definition tailored for sortingnetwork - many other variants exist!

Expander Graphs:probabilistic construction “easy”: take d (disjoint) random matchings

explicit construction is a deep mathematical problem with ties tonumber theory, group theory, combinatorics etc.

many applications in networking, complexity theory and coding theory

I. Course Intro and Sorting Networks Batcher’s Sorting Network 28

Page 153: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Expanders to Approximate Halvers

L R

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

I. Course Intro and Sorting Networks Batcher’s Sorting Network 29

Page 154: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Expanders to Approximate Halvers

L R

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

I. Course Intro and Sorting Networks Batcher’s Sorting Network 29

Page 155: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Expanders to Approximate Halvers

L R

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

I. Course Intro and Sorting Networks Batcher’s Sorting Network 29

Page 156: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Expanders to Approximate Halvers

L R

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

I. Course Intro and Sorting Networks Batcher’s Sorting Network 29

Page 157: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Expanders to Approximate Halvers

L R

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

I. Course Intro and Sorting Networks Batcher’s Sorting Network 29

Page 158: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Expanders to Approximate Halvers

L R

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

I. Course Intro and Sorting Networks Batcher’s Sorting Network 29

Page 159: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Expanders to Approximate Halvers

L R

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

I. Course Intro and Sorting Networks Batcher’s Sorting Network 29

Page 160: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Expanders to Approximate Halvers

L R

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

I. Course Intro and Sorting Networks Batcher’s Sorting Network 29

Page 161: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Expanders to Approximate Halvers

L R

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

I. Course Intro and Sorting Networks Batcher’s Sorting Network 29

Page 162: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd

⇒ ud ∈ X

Since u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )|

> |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 163: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputs

Y := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd

⇒ ud ∈ X

Since u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )|

> |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 164: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputs

For every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd

⇒ ud ∈ X

Since u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )|

> |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 165: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ Y

Let ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd

⇒ ud ∈ X

Since u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )|

> |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 166: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the output

Note that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd

⇒ ud ∈ X

Since u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )|

> |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 167: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the output

Note that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd

⇒ ud ∈ X

Since u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )|

> |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 168: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ X

Further: ud ≤ ut ≤ vt ≤ vd

⇒ ud ∈ X

Since u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )|

> |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 169: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd

⇒ ud ∈ XSince u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )|

> |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 170: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd ⇒ ud ∈ XSince u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )|

> |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 171: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd ⇒ ud ∈ XSince u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )|

> |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 172: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd ⇒ ud ∈ XSince u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )|

> |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 173: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd ⇒ ud ∈ XSince u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )| > |Y |+ min{µ|Y |, n/2− |Y |}

= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 174: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd ⇒ ud ∈ XSince u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )| > |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 175: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd ⇒ ud ∈ XSince u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )| > |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 176: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd ⇒ ud ∈ XSince u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )| > |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 177: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Existence of Approximate Halvers (not examinable)Proof:

X := keys with the k smallest inputsY := wires in lower half with k smallest outputsFor every u ∈ N(Y ): ∃ comparat. (u, v), v ∈ YLet ut , vt be their keys after the comparatorLet ud , vd be their keys at the outputNote that vd ∈ XFurther: ud ≤ ut ≤ vt ≤ vd ⇒ ud ∈ XSince u was arbitrary:

|Y |+ |N(Y )| ≤ k .

Since G is a bipartite (n, d , µ)-expander:

|Y |+ |N(Y )| > |Y |+ min{µ|Y |, n/2− |Y |}= min{(1 + µ)|Y |, n/2}.

Combining the two bounds above yields:

(1 + µ)|Y | ≤ k .

Same argument⇒ at most ε · k ,ε := 1/(µ+ 1), of the k largest input keys areplaced in b1, . . . , bn/2.

Here we used that k ≤ n/2

v

u

vd

ud

vt

ut

typical application of expander gaphs in parallel algorithmsMuch more work needed to construct the AKS sorting network

I. Course Intro and Sorting Networks Batcher’s Sorting Network 30

Page 178: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

AKS network vs. Batcher’s network

Donald E. Knuth (Stanford)

“Batcher’s method is muchbetter, unless n exceeds thetotal memory capacity of allcomputers on earth!”

Richard J. Lipton (Georgia Tech)

“The AKS sorting network isgalactic: it needs that n belarger than 278 or so to finallybe smaller than Batcher’snetwork for n items.”

I. Course Intro and Sorting Networks Batcher’s Sorting Network 31

Page 179: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Siblings of Sorting Network

sorts any input of size n

special case of Comparison Networks

Sorting Networks

creates a random permutation of n items

special case of Permutation Networks

Switching (Shuffling) Networks

balances any stream of tokens over n wires

special case of Balancing Networks

Counting Networks

7 2

2 7

comparator

<=>

7 ?

2 ?

switch

7 5

2 4

balancer

I. Course Intro and Sorting Networks Batcher’s Sorting Network 32

Page 180: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Siblings of Sorting Network

sorts any input of size n

special case of Comparison Networks

Sorting Networks

creates a random permutation of n items

special case of Permutation Networks

Switching (Shuffling) Networks

balances any stream of tokens over n wires

special case of Balancing Networks

Counting Networks

7 2

2 7

comparator

<=>

7 ?

2 ?

switch

7 5

2 4

balancer

I. Course Intro and Sorting Networks Batcher’s Sorting Network 32

Page 181: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Siblings of Sorting Network

sorts any input of size n

special case of Comparison Networks

Sorting Networks

creates a random permutation of n items

special case of Permutation Networks

Switching (Shuffling) Networks

balances any stream of tokens over n wires

special case of Balancing Networks

Counting Networks

7 2

2 7

comparator

<=>

7 ?

2 ?

switch

7 5

2 4

balancer

I. Course Intro and Sorting Networks Batcher’s Sorting Network 32

Page 182: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Outline

Outline of this Course

Some Highlights

Introduction to Sorting Networks

Batcher’s Sorting Network

Counting Networks

Load Balancing on Graphs

I. Course Intro and Sorting Networks Counting Networks 33

Page 183: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 184: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 185: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 186: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 187: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 188: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 189: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 190: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 191: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 192: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 193: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 194: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 195: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 196: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Counting Network

Processors collectively assign successive values from a given range.

Distributed Counting

Values could represent addresses in memoriesor destinations on an interconnection network

constructed in a similar manner like sorting networks

instead of comparators, consists of balancers

balancers are asynchronous flip-flops that forward tokens from itsinputs to one of its two outputs alternately (top, bottom, top,. . .)

Balancing Networks

Number of tokens differs by at most one

I. Course Intro and Sorting Networks Counting Networks 34

Page 197: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network

1. Let x1, x2, . . . , xn be the number of tokens (ever received) on thedesignated input wires

2. Let y1, y2, . . . , yn be the number of tokens (ever received) on thedesignated output wires

3. In a quiescent state:∑n

i=1 xi =∑n

i=1 yi

4. A counting network is a balancing network with the step-property:

0 ≤ yi − yj ≤ 1 for any i < j .

Counting Network (Formal Definition)

Bitonic Counting Network: Take Batcher’s Sorting Network and replaceeach comparator by a balancer.

I. Course Intro and Sorting Networks Counting Networks 35

Page 198: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network

1. Let x1, x2, . . . , xn be the number of tokens (ever received) on thedesignated input wires

2. Let y1, y2, . . . , yn be the number of tokens (ever received) on thedesignated output wires

3. In a quiescent state:∑n

i=1 xi =∑n

i=1 yi

4. A counting network is a balancing network with the step-property:

0 ≤ yi − yj ≤ 1 for any i < j .

Counting Network (Formal Definition)

Bitonic Counting Network: Take Batcher’s Sorting Network and replaceeach comparator by a balancer.

I. Course Intro and Sorting Networks Counting Networks 35

Page 199: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network

1. Let x1, x2, . . . , xn be the number of tokens (ever received) on thedesignated input wires

2. Let y1, y2, . . . , yn be the number of tokens (ever received) on thedesignated output wires

3. In a quiescent state:∑n

i=1 xi =∑n

i=1 yi

4. A counting network is a balancing network with the step-property:

0 ≤ yi − yj ≤ 1 for any i < j .

Counting Network (Formal Definition)

Bitonic Counting Network: Take Batcher’s Sorting Network and replaceeach comparator by a balancer.

I. Course Intro and Sorting Networks Counting Networks 35

Page 200: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

Proof (by induction on n being a power of 2)

Case n = 2 is clear, since MERGER[2] is a single balancern > 2:

Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 201: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

Consider a MERGER[n]. Then if the inputs x1, . . . , xn/2 and xn/2+1, . . . , xn

have the step property, then so does the output y1, . . . , yn.

Key Lemma

Proof (by induction on n being a power of 2)

Case n = 2 is clear, since MERGER[2] is a single balancern > 2:

Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 202: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)

Case n = 2 is clear, since MERGER[2] is a single balancern > 2:

Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 203: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancer

n > 2:

Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 204: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2:

Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 205: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2: Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 206: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2: Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 207: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2: Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 208: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2: Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 209: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2: Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 210: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2: Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 211: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2: Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′i

F1⇒ Z = d 12

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 212: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2: Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 213: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2: Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .

Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 214: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2: Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 215: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Correctness of the Bitonic Counting Network

Let x1, . . . , xn and y1, . . . , yn have the step property. Then:

1. We have∑n/2

i=1 x2i−1 =⌈ 1

2

∑ni=1 xi

⌉, and

∑n/2i=1 x2i =

⌊ 12

∑ni=1 xi

⌋2. If

∑ni=1 xi =

∑ni=1 yi , then xi = yi for i = 1, . . . , n.

3. If∑n

i=1 xi =∑n

i=1 yi + 1, then ∃! j = 1, 2, . . . , n with xj = yj + 1 and xi = yi for j 6= i .

Facts

z1

z2

z3

z4

z′1

z′2z′3

z′4

x1x2x3x4x5x6x7x8

Proof (by induction on n being a power of 2)Case n = 2 is clear, since MERGER[2] is a single balancern > 2: Let z1, . . . , zn/2 and z′1, . . . , z′n/2 be the outputs of the MERGER[n/2] subnetworks

IH⇒ z1, . . . , zn/2 and z′1, . . . , z′n/2 have the step property

Let Z :=∑n/2

i=1 zi and Z ′ :=∑n/2

i=1 z′iF1⇒ Z = d 1

2

∑n/2i=1 xie + b 1

2

∑ni=n/2+1 xic and Z ′ = b 1

2

∑n/2i=1 xic + d 1

2

∑ni=n/2+1 xie

Case 1: If Z = Z ′, then F2 implies the output of MERGER[n] is yi = z1+b(i−1)/2c X

Case 2: If |Z − Z ′| = 1, F3 implies zi = z′i for i = 1, . . . , n/2 except a unique j with zj 6= z′j .Balancer between zj and z′j will ensure that the step property holds.

I. Course Intro and Sorting Networks Counting Networks 36

Page 216: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 217: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1

111111111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 218: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1

1

11111111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 219: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 1

1

1111111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 220: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 11

1

111111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 221: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111

1

11111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 222: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 1111

1

1111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 223: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 11111

1

111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 224: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111

1

11

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 225: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 1111111

1

1

1

11111111111

1

11111111111111

1

1111111 1

2

2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 226: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 11111111

1

1

11111111111

1

11111111111111

1

1111111 1

2

2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 227: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

3

3 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 228: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

1

1111111111

1

11111111111111

1

1111111 1

2 2

2

2

2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 229: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

1

1

111111111

1

11111111111111

1

1111111 1

2 2

2

2

2

2

2

222222222222222222222222222222222

2

22222 2

33

3

33333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 230: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11

1

11111111

1

11111111111111

1

1111111 1

2 2

2

2 2

2

2

222222222222222222222222222222222

2

22222 2

33 3

3

3333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 231: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

111

1

1111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 33

3

333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 232: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

1111

1

111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

2

22222222222222222222222222222222

2

22222 2

33 333

3

33

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 233: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111

1

11111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

2

2

2222222222222222222222222222222

2

22222 2

33 3333

3

3

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 234: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

111111

1

1111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

22

2

222222222222222222222222222222

2

22222 2

33 33333

3

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 235: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

1111111

1

111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222

2

22222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 236: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111

1

11

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

2222

2

2222222222222222222222222222

2

22222 2

33 333333

3

3

33333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 237: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

111111111

1

1

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

22222

2

222222222222222222222222222

2

22222 2

33 333333

3

3

3

3333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 238: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

1111111111

1

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222

2

22222222222222222222222222

2

22222 2

33 333333

3

33

3

333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 239: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

2222222

2

2222222222222222222222222

2

22222 2

33 333333

3

333

3

33333

3

3 3 3 3 3 3 3

3

33333 3

4

4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 240: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

1

1111111111111

1

1111111 1

2 2

2

2 2 2

2

22222222

2

222222222222222222222222

2

22222 2

33 333333

3

3333

3

3333

3

3 3 3 3 3 3 3

3

33333 3

4

4

444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 241: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

1

1

111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222

2

22222222222222222222222

2

22222 2

33 333333

3

33333

3

333

3

3 3 3 3 3 3 3

3

33333 3

4 4

4

44444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 242: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11

1

11111111111

1

1111111 1

2 2

2

2 2 2

2

2222222222

2

2222222222222222222222

2

22222 2

33 333333

3

333333

3

33

3

3 3 3 3 3 3 3

3

33333 3

4 44

4

4444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 243: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

111

1

1111111111

1

1111111 1

2 2

2

2 2 2

2

22222222222

2

222222222222222222222

2

22222 2

33 333333

3

3333333

3

3

3

3 3 3 3 3 3 3

3

33333 3

4 444

4

444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 244: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

1111

1

111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222

2

22222222222222222222

2

22222 2

33 333333

3

33333333

3

3

3 3 3 3 3 3 3

3

33333 3

4 4444

4

44444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 245: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111

1

11111111

1

1111111 1

2 2

2

2 2 2

2

2222222222222

2

2222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 44444

4

4444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 246: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

111111

1

1111111

1

1111111 1

2 2

2

2 2 2

2

22222222222222

2

222222222222222222

2

22222 2

33 333333

3

333333333

3

3

3 3 3 3 3 3

3

33333 3

4 444444

4

444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 247: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

1111111

1

111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222

2

22222222222222222

2

22222 2

33 333333

3

333333333

3

3

3

3 3 3 3 3

3

33333 3

4 4444444

4

44444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 248: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111

1

11111

1

1111111 1

2 2

2

2 2 2

2

2222222222222222

2

2222222222222222

2

22222 2

33 333333

3

333333333

3

3 3

3

3 3 3 3

3

33333 3

4 44444444

4

4444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 249: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

111111111

1

1111

1

1111111 1

2 2

2

2 2 2

2

22222222222222222

2

222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3

3

3 3 3

3

33333 3

4 444444444

4

444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 250: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

1111111111

1

111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222

2

22222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3

3

3 3

3

33333 3

4 4444444444

4

44444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 251: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111

1

11

1

1111111 1

2 2

2

2 2 2

2

2222222222222222222

2

2222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3

3

3

3

33333 3

4 44444444444

4

4444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 252: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

111111111111

1

1

1

1111111 1

2 2

2

2 2 2

2

22222222222222222222

2

222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3

3

3

33333 3

4 444444444444

4

444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 253: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

1111111111111

1

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222

2

22222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333 3

4 4444444444444

4

44444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 254: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

2222222222222222222222

2

2222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

3

3333 3

4 44444444444444

4

4444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 255: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1

111111 1

2 2

2

2 2 2

2

22222222222222222222222

2

222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

3

3

333 3

4 444444444444444

4

444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6

666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 256: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1

1

11111 1

2 2

2

2 2 2

2

222222222222222222222222

2

22222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33

3

33 3

4 4444444444444444

4

44

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6

6

66666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 257: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

11

1

1111 1

2 2

2

2 2 2

2

2222222222222222222222222

2

2222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

333

3

3 3

4 44444444444444444

4

4

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 6

6

6666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 258: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

111

1

111 1

2 2

2

2 2 2

2

22222222222222222222222222

2

222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

3333

3

3

4 444444444444444444

4

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 66

6

666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 259: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111

1

11 1

2 2

2

2 2 2

2

222222222222222222222222222

2

22222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666

6

66666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 260: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

11111

1

1 1

2 2

2

2 2 2

2

2222222222222222222222222222

2

2222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4

444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 6666

6

6666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 261: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

111111

1

1

2 2

2

2 2 2

2

22222222222222222222222222222

2

222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4

4

44444444444

4

44444444444444444444444444444

4

4444444 4

5

5 55555

5

555555555555555

5

5 5 5

5

5 5

6 66666

6

666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 262: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111 1

2 2

2

2 2 2

2

222222222222222222222222222222

2

22

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

44

4

4444444444

4

44444444444444444444444444444

4

4444444 4

55

5

5555

5

555555555555555

5

5 5 5

5

5 5

6 666666

6

66666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 263: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

2222222222222222222222222222222

2

2

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

444

4

444444444

4

44444444444444444444444444444

4

4444444 4

55 5

5

555

5

555555555555555

5

5 5 5

5

5 5

6 6666666

6

6666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 264: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

22222222222222222222222222222222

2

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444

4

44444444

4

44444444444444444444444444444

4

4444444 4

55 55

5

55

5

555555555555555

5

5 5 5

5

5 5

6 66666666

6

666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 265: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

44444

4

4444444

4

44444444444444444444444444444

4

4444444 4

55 555

5

5

5

555555555555555

5

5 5 5

5

5 5

6 666666666

6

66666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 266: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

2

2222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

444444

4

444444

4

44444444444444444444444444444

4

4444444 4

55 5555

5

5

555555555555555

5

5 5 5

5

5 5

6 6666666666

6

6666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 267: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

2

2

222 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444

4

44444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 66666666666

6

666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 268: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22

2

22 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

44444444

4

4444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

5

55555555555555

5

5 5 5

5

5 5

6 666666666666

6

66

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 269: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

222

2

2 2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

444444444

4

444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

5

5

5555555555555

5

5 5 5

5

5 5

6 6666666666666

6

6

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 270: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

2222

2

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444

4

44

4

44444444444444444444444444444

4

4444444 4

55 55555

5

55

5

555555555555

5

5 5 5

5

5 5

6 66666666666666

6

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 271: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

44444444444

4

4

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555

5

55555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 272: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

444444444444

4

4

44444444444444444444444444444

4

4444444 4

55 55555

5

5555

5

5555555555

5

5 5 5

5

5 5

6 666666666666666

6

6

666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 273: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

55555

5

555555555

5

5 5 5

5

5 5

6 666666666666666

6

6

6

66666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 274: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

4

4444444444444444444444444444

4

4444444 4

55 55555

5

555555

5

55555555

5

5 5 5

5

5 5

6 666666666666666

6

66

6

6666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 275: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

4

4

444444444444444444444444444

4

4444444 4

55 55555

5

5555555

5

5555555

5

5 5 5

5

5 5

6 666666666666666

6

666

6

666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 276: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44

4

44444444444444444444444444

4

4444444 4

55 55555

5

55555555

5

555555

5

5 5 5

5

5 5

6 666666666666666

6

6666

6

66

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 277: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

444

4

4444444444444444444444444

4

4444444 4

55 55555

5

555555555

5

55555

5

5 5 5

5

5 5

6 666666666666666

6

66666

6

6

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 278: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

4444

4

444444444444444444444444

4

4444444 4

55 55555

5

5555555555

5

5555

5

5 5 5

5

5 5

6 666666666666666

6

666666

6

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 279: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444

4

44444444444444444444444

4

4444444 4

55 55555

5

55555555555

5

555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 280: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

444444

4

4444444444444444444444

4

4444444 4

55 55555

5

555555555555

5

55

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

6

6666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 281: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

4444444

4

444444444444444444444

4

4444444 4

55 55555

5

5555555555555

5

5

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

6

6

666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 282: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444

4

44444444444444444444

4

4444444 4

55 55555

5

55555555555555

5

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

66

6

66666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 283: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

444444444

4

4444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

666

6

6666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 284: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

4444444444

4

444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5

5 5

5

5 5

6 666666666666666

6

6666666

6

6666

6

666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 285: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444

4

44444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5

5

5

5

5 5

6 666666666666666

6

6666666

6

66666

6

66666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 286: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

444444444444

4

4444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5

5

5

5 5

6 666666666666666

6

6666666

6

666666

6

6666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 287: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

4444444444444

4

444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5 5

6 666666666666666

6

6666666

6

6666666

6

666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 288: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444

4

44444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666

6

66

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 289: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

444444444444444

4

4444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

666666666

6

6

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 290: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

4444444444444444

4

444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

6666666666

6

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 291: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444

4

44444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 292: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

444444444444444444

4

4444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6

666666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 293: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

4444444444444444444

4

444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6

6

66666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 294: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444

4

44444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

66

6

6666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 295: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

444444444444444444444

4

4444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

666

6

666 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 296: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

4444444444444444444444

4

444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666

6

66 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 297: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444

4

44444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

66666

6

6 6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 298: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

444444444444444444444444

4

4444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

666666

6

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 299: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

4444444444444444444444444

4

444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 300: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444

4

44

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 301: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

444444444444444444444444444

4

4

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 302: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

4444444444444444444444444444

4

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 303: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 304: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4

444444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 305: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4

4

44444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 306: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

44

4

4444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 307: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

444

4

444 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 308: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444

4

44 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 309: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

44444

4

4 4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 310: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

444444

4

4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 311: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444

4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 312: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Bitonic Counting Network in Action (Asychnronous Execution)

x1 y1

x2 y2

x3 y3

x4 y4

1 111111111

1

11111111111

1

11111111111111

1

1111111

1

2 2

2

2 2 2

2

222222222222222222222222222222222

2

22222

2

33 333333

3

333333333

3

3 3 3 3 3 3 3

3

33333

3

4 4444444444444444444

4

4444444444444

4

44444444444444444444444444444

4

4444444

4

55 55555

5

555555555555555

5

5 5 5

5

5

5

6 666666666666666

6

6666666

6

66666666666

6

6666666

6

Counting can be done as follows:Add local counter to each output wire i , toassign consecutive numbers i, i + n, i + 2 · n, . . .

I. Course Intro and Sorting Networks Counting Networks 37

Page 313: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

A Periodic Counting Network [Aspnes, Herlihy, Shavit, JACM 1994]

x1 y1

x2 y2

x3 y3

x4 y4

x5 y5

x6 y6

x7 y7

x8 y8

Consists of log n BLOCK[n] networks each of which has depth log n

I. Course Intro and Sorting Networks Counting Networks 38

Page 314: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

A Periodic Counting Network [Aspnes, Herlihy, Shavit, JACM 1994]

x1 y1

x2 y2

x3 y3

x4 y4

x5 y5

x6 y6

x7 y7

x8 y8

Consists of log n BLOCK[n] networks each of which has depth log n

I. Course Intro and Sorting Networks Counting Networks 38

Page 315: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.

Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wiresS corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 316: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.

Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wiresS corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 317: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.

Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wiresS corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 318: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting network

Consider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wiresS corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C

S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 319: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting network

Consider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wiresS corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 320: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to S

Define an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wiresS corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 321: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to S

Define an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wiresS corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 322: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.

C is a counting network⇒ all ones will be routed to the lower wiresS corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 323: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wires

S corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 324: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wires

S corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 325: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wires

S corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 326: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wires

S corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 327: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wires

S corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 328: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wiresS corresponds to C ⇒ all zeros will be routed to the lower wires

By the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 329: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wiresS corresponds to C ⇒ all zeros will be routed to the lower wires

By the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 330: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

From Counting to Sorting

If a network is a counting network, then it is also a sorting network.Counting vs. Sorting

The converse is not true!

Proof.Let C be a counting network, and S be the corresponding sorting networkConsider an input sequence a1, a2, . . . , an ∈ {0, 1}n to SDefine an input x1, x2, . . . , xn ∈ {0, 1}n to C by xi = 1 iff ai = 0.C is a counting network⇒ all ones will be routed to the lower wiresS corresponds to C ⇒ all zeros will be routed to the lower wiresBy the Zero-One Principle, S is a sorting network.

C S

1

0

0

1

0

0

1

1

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

0

1

1

0

0

I. Course Intro and Sorting Networks Counting Networks 39

Page 331: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Outline

Outline of this Course

Some Highlights

Introduction to Sorting Networks

Batcher’s Sorting Network

Counting Networks

Load Balancing on Graphs

I. Course Intro and Sorting Networks Load Balancing on Graphs 40

Page 332: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Communication Models: Diffusion vs. Matching

1

6

5 4

3

2 1

6

5 4

3

2

M =

12

14 0 0 0 1

414

12

14 0 0 0

0 14

12

14 0 0

0 0 14

12

14 0

0 0 0 14

12

14

14 0 0 0 1

412

M(t) =

12

12 0 0 0 0

12

12 0 0 0 0

0 0 0 0 0 00 0 0 1

212 0

0 0 0 12

12 0

0 0 0 0 0 0

I. Course Intro and Sorting Networks Load Balancing on Graphs 41

Page 333: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Communication Models: Diffusion vs. Matching

1

6

5 4

3

2 1

6

5 4

3

2

M =

12

14 0 0 0 1

414

12

14 0 0 0

0 14

12

14 0 0

0 0 14

12

14 0

0 0 0 14

12

14

14 0 0 0 1

412

M(t) =

12

12 0 0 0 0

12

12 0 0 0 0

0 0 0 0 0 00 0 0 1

212 0

0 0 0 12

12 0

0 0 0 0 0 0

I. Course Intro and Sorting Networks Load Balancing on Graphs 41

Page 334: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Smoothness of the Load Distribution

x t ∈ Rn be a load vector at round t

x denotes the average load

Want that x t converges for t →∞ to (x , x , . . . , x)!

`2-norm: Φt =√∑n

i=1(x ti − x)2

makespan: maxni=1 x t

i

discrepancy: maxni=1 x t

i −minni=1 xi .

Metrics

1.5

2

2.5

2

3

3.5

6.5

3

For this example:

Φt =√

02 + 02 + 3.52 + 0.52 + 12 + 12 + 1.52 + 0.52 =√

17

maxni=1 x t

i = 6.5

maxni=1 x t

i −minni=1 x t

i = 5

I. Course Intro and Sorting Networks Load Balancing on Graphs 42

Page 335: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Smoothness of the Load Distribution

x t ∈ Rn be a load vector at round t

x denotes the average load

Want that x t converges for t →∞ to (x , x , . . . , x)!

`2-norm: Φt =√∑n

i=1(x ti − x)2

makespan: maxni=1 x t

i

discrepancy: maxni=1 x t

i −minni=1 xi .

Metrics

1.5

2

2.5

2

3

3.5

6.5

3

For this example:

Φt =√

02 + 02 + 3.52 + 0.52 + 12 + 12 + 1.52 + 0.52 =√

17

maxni=1 x t

i = 6.5

maxni=1 x t

i −minni=1 x t

i = 5

I. Course Intro and Sorting Networks Load Balancing on Graphs 42

Page 336: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Smoothness of the Load Distribution

x t ∈ Rn be a load vector at round t

x denotes the average load

Want that x t converges for t →∞ to (x , x , . . . , x)!

`2-norm: Φt =√∑n

i=1(x ti − x)2

makespan: maxni=1 x t

i

discrepancy: maxni=1 x t

i −minni=1 xi .

Metrics

1.5

2

2.5

2

3

3.5

6.5

3

For this example:

Φt =√

02 + 02 + 3.52 + 0.52 + 12 + 12 + 1.52 + 0.52 =√

17

maxni=1 x t

i = 6.5

maxni=1 x t

i −minni=1 x t

i = 5

I. Course Intro and Sorting Networks Load Balancing on Graphs 42

Page 337: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Smoothness of the Load Distribution

x t ∈ Rn be a load vector at round t

x denotes the average load

Want that x t converges for t →∞ to (x , x , . . . , x)!

`2-norm: Φt =√∑n

i=1(x ti − x)2

makespan: maxni=1 x t

i

discrepancy: maxni=1 x t

i −minni=1 xi .

Metrics

1.5

2

2.5

2

3

3.5

6.5

3

For this example:

Φt =√

02 + 02 + 3.52 + 0.52 + 12 + 12 + 1.52 + 0.52 =√

17

maxni=1 x t

i = 6.5

maxni=1 x t

i −minni=1 x t

i = 5

I. Course Intro and Sorting Networks Load Balancing on Graphs 42

Page 338: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Smoothness of the Load Distribution

x t ∈ Rn be a load vector at round t

x denotes the average load

Want that x t converges for t →∞ to (x , x , . . . , x)!

`2-norm: Φt =√∑n

i=1(x ti − x)2

makespan: maxni=1 x t

i

discrepancy: maxni=1 x t

i −minni=1 xi .

Metrics

1.5

2

2.5

2

3

3.5

6.5

3

For this example:

Φt =√

02 + 02 + 3.52 + 0.52 + 12 + 12 + 1.52 + 0.52 =√

17

maxni=1 x t

i = 6.5

maxni=1 x t

i −minni=1 x t

i = 5

I. Course Intro and Sorting Networks Load Balancing on Graphs 42

Page 339: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Smoothness of the Load Distribution

x t ∈ Rn be a load vector at round t

x denotes the average load

Want that x t converges for t →∞ to (x , x , . . . , x)!

`2-norm: Φt =√∑n

i=1(x ti − x)2

makespan: maxni=1 x t

i

discrepancy: maxni=1 x t

i −minni=1 xi .

Metrics

1.5

2

2.5

2

3

3.5

6.5

3

For this example:

Φt =√

02 + 02 + 3.52 + 0.52 + 12 + 12 + 1.52 + 0.52 =√

17

maxni=1 x t

i = 6.5

maxni=1 x t

i −minni=1 x t

i = 5

I. Course Intro and Sorting Networks Load Balancing on Graphs 42

Page 340: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion Matrix

Given an undirected, connected graph G = (V ,E) and a diffusion pa-rameter α > 0, the diffusion matrix M is defined as follows:

Mij =

α if (i, j) ∈ E ,1− α deg(i) if i = j,0 otherwise.

Further let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1are the eigenvalues of M.

Diffusion Matrix

How to pick α for a d-regular graph?

α = 1d may lead to oscillation (if graph is bipartite)

α = 1d+1 ensures convergence

α = 12d ensures convergence (and all eigenvalues of M are non-negative)

First-Order Diffusion: Load vector x t satisfies

x t = M · x t−1.

# neighbors of i

This can be also seen as a random walk on G!

I. Course Intro and Sorting Networks Load Balancing on Graphs 43

Page 341: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion Matrix

Given an undirected, connected graph G = (V ,E) and a diffusion pa-rameter α > 0, the diffusion matrix M is defined as follows:

Mij =

α if (i, j) ∈ E ,1− α deg(i) if i = j,0 otherwise.

Further let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1are the eigenvalues of M.

Diffusion Matrix

How to pick α for a d-regular graph?

α = 1d may lead to oscillation (if graph is bipartite)

α = 1d+1 ensures convergence

α = 12d ensures convergence (and all eigenvalues of M are non-negative)

First-Order Diffusion: Load vector x t satisfies

x t = M · x t−1.

# neighbors of i

This can be also seen as a random walk on G!

I. Course Intro and Sorting Networks Load Balancing on Graphs 43

Page 342: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion Matrix

Given an undirected, connected graph G = (V ,E) and a diffusion pa-rameter α > 0, the diffusion matrix M is defined as follows:

Mij =

α if (i, j) ∈ E ,1− α deg(i) if i = j,0 otherwise.

Further let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1are the eigenvalues of M.

Diffusion Matrix

How to pick α for a d-regular graph?

α = 1d may lead to oscillation (if graph is bipartite)

α = 1d+1 ensures convergence

α = 12d ensures convergence (and all eigenvalues of M are non-negative)

First-Order Diffusion: Load vector x t satisfies

x t = M · x t−1.

# neighbors of i

This can be also seen as a random walk on G!

I. Course Intro and Sorting Networks Load Balancing on Graphs 43

Page 343: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion Matrix

Given an undirected, connected graph G = (V ,E) and a diffusion pa-rameter α > 0, the diffusion matrix M is defined as follows:

Mij =

α if (i, j) ∈ E ,1− α deg(i) if i = j,0 otherwise.

Further let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1are the eigenvalues of M.

Diffusion Matrix

How to pick α for a d-regular graph?

α = 1d may lead to oscillation (if graph is bipartite)

α = 1d+1 ensures convergence

α = 12d ensures convergence (and all eigenvalues of M are non-negative)

First-Order Diffusion: Load vector x t satisfies

x t = M · x t−1.

# neighbors of i

This can be also seen as a random walk on G!

I. Course Intro and Sorting Networks Load Balancing on Graphs 43

Page 344: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion Matrix

Given an undirected, connected graph G = (V ,E) and a diffusion pa-rameter α > 0, the diffusion matrix M is defined as follows:

Mij =

α if (i, j) ∈ E ,1− α deg(i) if i = j,0 otherwise.

Further let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1are the eigenvalues of M.

Diffusion Matrix

How to pick α for a d-regular graph?

α = 1d may lead to oscillation (if graph is bipartite)

α = 1d+1 ensures convergence

α = 12d ensures convergence (and all eigenvalues of M are non-negative)

First-Order Diffusion: Load vector x t satisfies

x t = M · x t−1.

# neighbors of i

This can be also seen as a random walk on G!

I. Course Intro and Sorting Networks Load Balancing on Graphs 43

Page 345: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion Matrix

Given an undirected, connected graph G = (V ,E) and a diffusion pa-rameter α > 0, the diffusion matrix M is defined as follows:

Mij =

α if (i, j) ∈ E ,1− α deg(i) if i = j,0 otherwise.

Further let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1are the eigenvalues of M.

Diffusion Matrix

How to pick α for a d-regular graph?

α = 1d may lead to oscillation (if graph is bipartite)

α = 1d+1 ensures convergence

α = 12d ensures convergence (and all eigenvalues of M are non-negative)

First-Order Diffusion: Load vector x t satisfies

x t = M · x t−1.

# neighbors of i

This can be also seen as a random walk on G!

I. Course Intro and Sorting Networks Load Balancing on Graphs 43

Page 346: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

1D grid

γ(M) ≈ 1− 1n2

2D grid

γ(M) ≈ 1− 1n

3D grid

γ(M) ≈ 1− 1n2/3

Complete Graph

γ(M) ≈ 0

Random Graph

γ(M) < 1

Hypercube

γ(M) ≈ 1− 1log n

γ(M) ∈ (0,1] measures connectivity of G

I. Course Intro and Sorting Networks Load Balancing on Graphs 44

Page 347: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

1D grid

γ(M) ≈ 1− 1n2

2D grid

γ(M) ≈ 1− 1n

3D grid

γ(M) ≈ 1− 1n2/3

Complete Graph

γ(M) ≈ 0

Random Graph

γ(M) < 1

Hypercube

γ(M) ≈ 1− 1log n

γ(M) ∈ (0,1] measures connectivity of G

I. Course Intro and Sorting Networks Load Balancing on Graphs 44

Page 348: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

1D grid

γ(M) ≈ 1− 1n2

2D grid

γ(M) ≈ 1− 1n

3D grid

γ(M) ≈ 1− 1n2/3

Complete Graph

γ(M) ≈ 0

Random Graph

γ(M) < 1

Hypercube

γ(M) ≈ 1− 1log n

γ(M) ∈ (0,1] measures connectivity of G

I. Course Intro and Sorting Networks Load Balancing on Graphs 44

Page 349: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

1D grid

γ(M) ≈ 1− 1n2

2D grid

γ(M) ≈ 1− 1n

3D grid

γ(M) ≈ 1− 1n2/3

Complete Graph

γ(M) ≈ 0

Random Graph

γ(M) < 1

Hypercube

γ(M) ≈ 1− 1log n

γ(M) ∈ (0,1] measures connectivity of G

I. Course Intro and Sorting Networks Load Balancing on Graphs 44

Page 350: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

1D grid

γ(M) ≈ 1− 1n2

2D grid

γ(M) ≈ 1− 1n

3D grid

γ(M) ≈ 1− 1n2/3

Complete Graph

γ(M) ≈ 0

Random Graph

γ(M) < 1

Hypercube

γ(M) ≈ 1− 1log n

γ(M) ∈ (0,1] measures connectivity of G

I. Course Intro and Sorting Networks Load Balancing on Graphs 44

Page 351: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

1D grid

γ(M) ≈ 1− 1n2

2D grid

γ(M) ≈ 1− 1n

3D grid

γ(M) ≈ 1− 1n2/3

Complete Graph

γ(M) ≈ 0

Random Graph

γ(M) < 1

Hypercube

γ(M) ≈ 1− 1log n

γ(M) ∈ (0,1] measures connectivity of G

I. Course Intro and Sorting Networks Load Balancing on Graphs 44

Page 352: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

1D grid

γ(M) ≈ 1− 1n2

2D grid

γ(M) ≈ 1− 1n

3D grid

γ(M) ≈ 1− 1n2/3

Complete Graph

γ(M) ≈ 0

Random Graph

γ(M) < 1

Hypercube

γ(M) ≈ 1− 1log n

γ(M) ∈ (0,1] measures connectivity of G

I. Course Intro and Sorting Networks Load Balancing on Graphs 44

Page 353: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

1.000

0.000

0.000

0.000

0.000

0.000

0.000

0.000

0.000

0.000

0.000

0.000

Step: 0

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 354: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.500

0.250

0.000

0.000

0.000

0.000

0.000

0.000

0.000

0.000

0.000

0.250

Step: 1

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 355: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.375

0.250

0.062

0.000

0.000

0.000

0.000

0.000

0.000

0.000

0.062

0.250

Step: 2

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 356: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.312

0.234

0.094

0.016

0.000

0.000

0.000

0.000

0.000

0.016

0.094

0.234

Step: 3

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 357: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.273

0.219

0.109

0.031

0.004

0.000

0.000

0.000

0.004

0.031

0.109

0.219

Step: 4

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 358: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.246

0.205

0.117

0.044

0.010

0.001

0.000

0.001

0.010

0.044

0.117

0.205

Step: 5

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 359: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.226

0.193

0.121

0.054

0.016

0.003

0.000

0.003

0.016

0.054

0.121

0.193

Step: 6

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 360: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.209

0.183

0.122

0.061

0.022

0.006

0.002

0.006

0.022

0.061

0.122

0.183

Step: 7

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 361: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.196

0.175

0.122

0.067

0.028

0.009

0.004

0.009

0.028

0.067

0.122

0.175

Step: 8

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 362: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.185

0.167

0.121

0.071

0.033

0.012

0.006

0.012

0.033

0.071

0.121

0.167

Step: 9

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 363: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.176

0.160

0.120

0.074

0.037

0.016

0.009

0.016

0.037

0.074

0.120

0.160

Step: 10

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 364: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.168

0.154

0.119

0.076

0.041

0.020

0.013

0.020

0.041

0.076

0.119

0.154

Step: 11

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 365: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.161

0.149

0.117

0.078

0.044

0.023

0.016

0.023

0.044

0.078

0.117

0.149

Step: 12

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 366: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.155

0.144

0.115

0.079

0.048

0.027

0.020

0.027

0.048

0.079

0.115

0.144

Step: 13

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 367: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.149

0.139

0.113

0.080

0.050

0.030

0.023

0.030

0.050

0.080

0.113

0.139

Step: 14

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 368: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.144

0.135

0.112

0.081

0.053

0.033

0.027

0.033

0.053

0.081

0.112

0.135

Step: 15

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 369: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.140

0.132

0.110

0.082

0.055

0.037

0.030

0.037

0.055

0.082

0.110

0.132

Step: 16

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 370: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.136

0.128

0.108

0.082

0.057

0.040

0.033

0.040

0.057

0.082

0.108

0.128

Step: 17

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 371: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.132

0.125

0.107

0.082

0.059

0.042

0.036

0.042

0.059

0.082

0.107

0.125

Step: 18

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 372: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.129

0.122

0.105

0.083

0.061

0.045

0.039

0.045

0.061

0.083

0.105

0.122

Step: 19

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 373: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.126

0.120

0.104

0.083

0.062

0.048

0.042

0.048

0.062

0.083

0.104

0.120

Step: 20

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 374: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.123

0.117

0.103

0.083

0.064

0.050

0.045

0.050

0.064

0.083

0.103

0.117

Step: 21

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 375: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.120

0.115

0.101

0.083

0.065

0.052

0.047

0.052

0.065

0.083

0.101

0.115

Step: 22

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 376: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.117

0.113

0.100

0.083

0.066

0.054

0.050

0.054

0.066

0.083

0.100

0.113

Step: 23

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 377: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.115

0.111

0.099

0.083

0.067

0.056

0.052

0.056

0.067

0.083

0.099

0.111

Step: 24

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 378: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.113

0.109

0.098

0.083

0.069

0.058

0.054

0.058

0.069

0.083

0.098

0.109

Step: 25

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 379: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.111

0.107

0.097

0.083

0.070

0.060

0.056

0.060

0.070

0.083

0.097

0.107

Step: 26

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 380: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.109

0.106

0.096

0.083

0.070

0.061

0.058

0.061

0.070

0.083

0.096

0.106

Step: 27

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 381: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.107

0.104

0.095

0.083

0.071

0.063

0.059

0.063

0.071

0.083

0.095

0.104

Step: 28

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 382: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.106

0.103

0.094

0.083

0.072

0.064

0.061

0.064

0.072

0.083

0.094

0.103

Step: 29

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 383: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.104

0.101

0.094

0.083

0.073

0.065

0.063

0.065

0.073

0.083

0.094

0.101

Step: 30

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 384: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.103

0.100

0.093

0.083

0.074

0.067

0.064

0.067

0.074

0.083

0.093

0.100

Step: 31

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 385: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.101

0.099

0.092

0.083

0.074

0.068

0.065

0.068

0.074

0.083

0.092

0.099

Step: 32

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 386: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.100

0.098

0.092

0.083

0.075

0.069

0.066

0.069

0.075

0.083

0.092

0.098

Step: 33

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 387: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.099

0.097

0.091

0.083

0.075

0.070

0.068

0.070

0.075

0.083

0.091

0.097

Step: 34

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 388: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.098

0.096

0.091

0.083

0.076

0.071

0.069

0.071

0.076

0.083

0.091

0.096

Step: 35

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 389: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.097

0.095

0.090

0.083

0.076

0.071

0.070

0.071

0.076

0.083

0.090

0.095

Step: 36

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 390: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.096

0.094

0.090

0.083

0.077

0.072

0.071

0.072

0.077

0.083

0.090

0.094

Step: 37

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 391: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.095

0.094

0.089

0.083

0.077

0.073

0.071

0.073

0.077

0.083

0.089

0.094

Step: 38

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 392: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.094

0.093

0.089

0.083

0.078

0.074

0.072

0.074

0.078

0.083

0.089

0.093

Step: 39

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 393: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.094

0.092

0.089

0.083

0.078

0.074

0.073

0.074

0.078

0.083

0.089

0.092

Step: 40

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 394: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.093

0.092

0.088

0.083

0.078

0.075

0.074

0.075

0.078

0.083

0.088

0.092

Step: 41

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 395: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.092

0.091

0.088

0.083

0.079

0.075

0.074

0.075

0.079

0.083

0.088

0.091

Step: 42

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 396: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.092

0.091

0.088

0.083

0.079

0.076

0.075

0.076

0.079

0.083

0.088

0.091

Step: 43

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 397: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.091

0.090

0.087

0.083

0.079

0.077

0.075

0.077

0.079

0.083

0.087

0.090

Step: 44

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 398: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.091

0.090

0.087

0.083

0.080

0.077

0.076

0.077

0.080

0.083

0.087

0.090

Step: 45

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 399: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.090

0.089

0.087

0.083

0.080

0.077

0.076

0.077

0.080

0.083

0.087

0.089

Step: 46

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 400: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.090

0.089

0.087

0.083

0.080

0.078

0.077

0.078

0.080

0.083

0.087

0.089

Step: 47

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 401: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.089

0.089

0.086

0.083

0.080

0.078

0.077

0.078

0.080

0.083

0.086

0.089

Step: 48

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 402: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.089

0.088

0.086

0.083

0.081

0.079

0.078

0.079

0.081

0.083

0.086

0.088

Step: 49

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 403: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Diffusion of Load on a Ring

0.089

0.088

0.086

0.083

0.081

0.079

0.078

0.079

0.081

0.083

0.086

0.088

Step: 50

I. Course Intro and Sorting Networks Load Balancing on Graphs 45

Page 404: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:

Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn

=n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met

= M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2

=n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 405: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:

Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn

=n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met

= M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2

=n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 406: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:Let et = x t − x , where x is the column vector with all entries set to x

Express et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn

=n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met

= M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2

=n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 407: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn

=n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met

= M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2

=n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 408: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn =n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met

= M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2

=n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 409: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn =n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met

= M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2

=n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 410: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn =n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met = M ·

(n∑

i=2

αivi

)

=n∑

i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2

=n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 411: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn =n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met = M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2

=n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 412: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn =n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met = M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2

=n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 413: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn =n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met = M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2 =n∑

i=2

α2i µ

2i ‖vi‖2

2

≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 414: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn =n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met = M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2 =n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2

= γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 415: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn =n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met = M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2 =n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 416: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Upper Bound)

Let γ(M) := maxµi 6=1 |µi |, where µ1 = 1 > µ2 ≥ · · · ≥ µn ≥ −1 are theeigenvalues of M. Then for any iteration t ,

Φt ≤ γ(M)t · Φ0.

Lemma

Proof:Let et = x t − x , where x is the column vector with all entries set to xExpress et through the orthogonal basis given by the eigenvectors of M:

et = α1 · v1 + α2 · v2 + · · ·+ αn · vn =n∑

i=2

αi · vi .

For the first order diffusion scheme,

et+1 = Met = M ·

(n∑

i=2

αivi

)=

n∑i=2

αiµivi .

Taking norms and using that the vi ’s are orthogonal,

‖et+1‖22 = ‖Met‖2

2 =n∑

i=2

α2i µ

2i ‖vi‖2

2 ≤ γ2n∑

i=2

α2i ‖vi‖2

2 = γ2 · ‖et‖22

et is orthogonal to v1

I. Course Intro and Sorting Networks Load Balancing on Graphs 46

Page 417: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Lower Bound)

For any eigenvalue µi , 1 ≤ i ≤ n, there is an initial load vector x0 so that

Φt = µti · Φ0.

Lemma

Proof:

Let x0 = x + vi , where vi is the eigenvector corresponding to µi

Then

et = Met−1 = M te0 = M tvi = µti vi ,

and

(Φt )2 = ‖et‖22 = µ2t

i ‖vi‖22 = µ2t

i (Φ0)2.

I. Course Intro and Sorting Networks Load Balancing on Graphs 47

Page 418: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Lower Bound)

For any eigenvalue µi , 1 ≤ i ≤ n, there is an initial load vector x0 so that

Φt = µti · Φ0.

Lemma

Proof:

Let x0 = x + vi , where vi is the eigenvector corresponding to µi

Then

et = Met−1 = M te0 = M tvi = µti vi ,

and

(Φt )2 = ‖et‖22 = µ2t

i ‖vi‖22 = µ2t

i (Φ0)2.

I. Course Intro and Sorting Networks Load Balancing on Graphs 47

Page 419: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Lower Bound)

For any eigenvalue µi , 1 ≤ i ≤ n, there is an initial load vector x0 so that

Φt = µti · Φ0.

Lemma

Proof:

Let x0 = x + vi , where vi is the eigenvector corresponding to µi

Then

et = Met−1 = M te0 = M tvi = µti vi ,

and

(Φt )2 = ‖et‖22 = µ2t

i ‖vi‖22 = µ2t

i (Φ0)2.

I. Course Intro and Sorting Networks Load Balancing on Graphs 47

Page 420: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Lower Bound)

For any eigenvalue µi , 1 ≤ i ≤ n, there is an initial load vector x0 so that

Φt = µti · Φ0.

Lemma

Proof:

Let x0 = x + vi , where vi is the eigenvector corresponding to µi

Then

et = Met−1 = M te0 = M tvi = µti vi ,

and

(Φt )2 = ‖et‖22 = µ2t

i ‖vi‖22 = µ2t

i (Φ0)2.

I. Course Intro and Sorting Networks Load Balancing on Graphs 47

Page 421: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Lower Bound)

For any eigenvalue µi , 1 ≤ i ≤ n, there is an initial load vector x0 so that

Φt = µti · Φ0.

Lemma

Proof:

Let x0 = x + vi , where vi is the eigenvector corresponding to µi

Then

et = Met−1 = M te0 = M tvi = µti vi ,

and

(Φt )2 = ‖et‖22 = µ2t

i ‖vi‖22 = µ2t

i (Φ0)2.

I. Course Intro and Sorting Networks Load Balancing on Graphs 47

Page 422: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Convergence of the Quadratic Error (Lower Bound)

For any eigenvalue µi , 1 ≤ i ≤ n, there is an initial load vector x0 so that

Φt = µti · Φ0.

Lemma

Proof:

Let x0 = x + vi , where vi is the eigenvector corresponding to µi

Then

et = Met−1 = M te0 = M tvi = µti vi ,

and

(Φt )2 = ‖et‖22 = µ2t

i ‖vi‖22 = µ2t

i (Φ0)2.

I. Course Intro and Sorting Networks Load Balancing on Graphs 47

Page 423: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Summary and Outlook: Idealised versus Discrete Case

Idealised Case

x t = M · x t−1

= M t · x0

Linear System

corresponds to Markov chain

well-understood

Given any load vector x0, the num-ber of iterations until x t satisfiesΦt ≤ ε is at most log(Φ0/ε)

1−γ(M).

Discrete Case

y t = M · y t−1 + ∆t

= M t · y0 +t∑

s=1

M t−s ·∆s

Non-Linear System

rounding of a Markov chain

harder to analyze

How close can it be madeto the idealised case?

Here load consists of integersthat cannot be divided further.

Rounding Error

I. Course Intro and Sorting Networks Load Balancing on Graphs 48

Page 424: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Summary and Outlook: Idealised versus Discrete Case

Idealised Case

x t = M · x t−1

= M t · x0

Linear System

corresponds to Markov chain

well-understood

Given any load vector x0, the num-ber of iterations until x t satisfiesΦt ≤ ε is at most log(Φ0/ε)

1−γ(M).

Discrete Case

y t = M · y t−1 + ∆t

= M t · y0 +t∑

s=1

M t−s ·∆s

Non-Linear System

rounding of a Markov chain

harder to analyze

How close can it be madeto the idealised case?

Here load consists of integersthat cannot be divided further.

Rounding Error

I. Course Intro and Sorting Networks Load Balancing on Graphs 48

Page 425: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Summary and Outlook: Idealised versus Discrete Case

Idealised Case

x t = M · x t−1

= M t · x0

Linear System

corresponds to Markov chain

well-understood

Given any load vector x0, the num-ber of iterations until x t satisfiesΦt ≤ ε is at most log(Φ0/ε)

1−γ(M).

Discrete Case

y t = M · y t−1 + ∆t

= M t · y0 +t∑

s=1

M t−s ·∆s

Non-Linear System

rounding of a Markov chain

harder to analyze

How close can it be madeto the idealised case?

Here load consists of integersthat cannot be divided further.

Rounding Error

I. Course Intro and Sorting Networks Load Balancing on Graphs 48

Page 426: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Summary and Outlook: Idealised versus Discrete Case

Idealised Case

x t = M · x t−1

= M t · x0

Linear System

corresponds to Markov chain

well-understood

Given any load vector x0, the num-ber of iterations until x t satisfiesΦt ≤ ε is at most log(Φ0/ε)

1−γ(M).

Discrete Case

y t = M · y t−1 + ∆t

= M t · y0 +t∑

s=1

M t−s ·∆s

Non-Linear System

rounding of a Markov chain

harder to analyze

How close can it be madeto the idealised case?

Here load consists of integersthat cannot be divided further.

Rounding Error

I. Course Intro and Sorting Networks Load Balancing on Graphs 48

Page 427: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Summary and Outlook: Idealised versus Discrete Case

Idealised Case

x t = M · x t−1

= M t · x0

Linear System

corresponds to Markov chain

well-understood

Given any load vector x0, the num-ber of iterations until x t satisfiesΦt ≤ ε is at most log(Φ0/ε)

1−γ(M).

Discrete Case

y t = M · y t−1 + ∆t

= M t · y0 +t∑

s=1

M t−s ·∆s

Non-Linear System

rounding of a Markov chain

harder to analyze

How close can it be madeto the idealised case?

Here load consists of integersthat cannot be divided further.

Rounding Error

I. Course Intro and Sorting Networks Load Balancing on Graphs 48

Page 428: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Summary and Outlook: Idealised versus Discrete Case

Idealised Case

x t = M · x t−1

= M t · x0

Linear System

corresponds to Markov chain

well-understood

Given any load vector x0, the num-ber of iterations until x t satisfiesΦt ≤ ε is at most log(Φ0/ε)

1−γ(M).

Discrete Case

y t = M · y t−1 + ∆t

= M t · y0 +t∑

s=1

M t−s ·∆s

Non-Linear System

rounding of a Markov chain

harder to analyze

How close can it be madeto the idealised case?

Here load consists of integersthat cannot be divided further.

Rounding Error

I. Course Intro and Sorting Networks Load Balancing on Graphs 48

Page 429: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Summary and Outlook: Idealised versus Discrete Case

Idealised Case

x t = M · x t−1

= M t · x0

Linear System

corresponds to Markov chain

well-understood

Given any load vector x0, the num-ber of iterations until x t satisfiesΦt ≤ ε is at most log(Φ0/ε)

1−γ(M).

Discrete Case

y t = M · y t−1 + ∆t

= M t · y0 +t∑

s=1

M t−s ·∆s

Non-Linear System

rounding of a Markov chain

harder to analyze

How close can it be madeto the idealised case?

Here load consists of integersthat cannot be divided further.

Rounding Error

I. Course Intro and Sorting Networks Load Balancing on Graphs 48

Page 430: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Summary and Outlook: Idealised versus Discrete Case

Idealised Case

x t = M · x t−1

= M t · x0

Linear System

corresponds to Markov chain

well-understood

Given any load vector x0, the num-ber of iterations until x t satisfiesΦt ≤ ε is at most log(Φ0/ε)

1−γ(M).

Discrete Case

y t = M · y t−1 + ∆t

= M t · y0 +t∑

s=1

M t−s ·∆s

Non-Linear System

rounding of a Markov chain

harder to analyze

How close can it be madeto the idealised case?

Here load consists of integersthat cannot be divided further.

Rounding Error

I. Course Intro and Sorting Networks Load Balancing on Graphs 48

Page 431: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Summary and Outlook: Idealised versus Discrete Case

Idealised Case

x t = M · x t−1

= M t · x0

Linear System

corresponds to Markov chain

well-understood

Given any load vector x0, the num-ber of iterations until x t satisfiesΦt ≤ ε is at most log(Φ0/ε)

1−γ(M).

Discrete Case

y t = M · y t−1 + ∆t

= M t · y0 +t∑

s=1

M t−s ·∆s

Non-Linear System

rounding of a Markov chain

harder to analyze

How close can it be madeto the idealised case?

Here load consists of integersthat cannot be divided further.

Rounding Error

I. Course Intro and Sorting Networks Load Balancing on Graphs 48

Page 432: I. Course Intro and Sorting Networks · permutation matrix of order n which represents an n-cycle (we assume * This particular transformation was chosen to make the d1j of the original

Summary and Outlook: Idealised versus Discrete Case

Idealised Case

x t = M · x t−1

= M t · x0

Linear System

corresponds to Markov chain

well-understood

Given any load vector x0, the num-ber of iterations until x t satisfiesΦt ≤ ε is at most log(Φ0/ε)

1−γ(M).

Discrete Case

y t = M · y t−1 + ∆t

= M t · y0 +t∑

s=1

M t−s ·∆s

Non-Linear System

rounding of a Markov chain

harder to analyze

How close can it be madeto the idealised case?

Here load consists of integersthat cannot be divided further.

Rounding Error

I. Course Intro and Sorting Networks Load Balancing on Graphs 48