Title: Comparison Networks
1Comparison Networks
- Sorting
- Sorting binary values
- Sorting arbitrary numbers
- Implementing symmetric functions
2Sorting Algorithms
Example
Order of comparisons not fixed in advance.
Not readily implementable in hardware.
3Sorting Networks
Order of comparisons fixed in advance.
Readily implementable in hardware.
4Sorting Networks (binary values)
inputs
outputs
1
0
0
0
0
0
Sorting Network
1
0
0
1
0
1
1
1
1
1
5Comparator (2-sorter)
outputs
inputs
x
min(x, y)
C
y
max(x, y)
6Comparator (2-sorter)
AON Implementation
outputs
inputs
x
min(x, y)
max(x, y)
y
7Comparator (2-sorter)
outputs
inputs
min(x, y)
x
max(x, y)
y
8Comparison Network
9Comparison Network
n / 2 comparisons per stage
10Sorting Network
Any ideas?
11Sorting Network
inputs
outputs
12Insertion Sort Network
inputs
outputs
depth 2n 3
13Batcher Sorting Network, n 4
14Batcher Sorting Network, n 8
n 4
n 4
15Lemma 1
Any subsequence of a sorted sequence is a sorted
sequence.
0
0
0
0
0
1
1
1
1
1
1
1
1
16Lemma 2
For a sorted sequence, the number of 0s in the
even subsequence is either equal to, or one
greater than, the number of 0s in the odd
subsequence.
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
even
odd
17Lemma 3
For two sorted sequences and
denotes the the number of 0s in
denotes the even subsequence of
denotes the odd subsequence of
18Lemma 3
19Lemma 3
For two sorted sequences and
(by Lemma 2)
(by Lemma 2)
20Merge Network
21Merge Network (pf.)
(by Lemma 1)
(by Lemma 1)
22Merge Network (pf.)
23Merge Network (pf.)
24Merge Network (pf.)
0
0
0
0
1
0
1
0
0
0
0
1
0
1
1
1
25Batcher Sorting Network
26Batcher Sorting Network, n 4
Sort2
Sort2
27Batcher Sorting Network, n 8
Sort4
Sort4
28Sorting Networks
Batcher
AKS (Chvátal)
29Implementing XOR
30Implementing XOR
Sorting Network
31Symmetric Functions
Sorting Network