Comparison Networks - PowerPoint PPT Presentation

1 / 67
About This Presentation
Title:

Comparison Networks

Description:

Comparison Networks Sorting Sorting binary values Sorting arbitrary numbers Implementing symmetric functions Proof: Zero-One Principle Sorting Network . . . . . . . . . – PowerPoint PPT presentation

Number of Views:93
Avg rating:3.0/5.0
Slides: 68
Provided by: Jeho1
Category:

less

Transcript and Presenter's Notes

Title: Comparison Networks


1
Comparison Networks
  • Sorting
  • Sorting binary values
  • Sorting arbitrary numbers
  • Implementing symmetric functions

2
Sorting Algorithms
Example
Order of comparisons not fixed in advance.
Not readily implementable in hardware.
3
Sorting Networks
Order of comparisons fixed in advance.
Readily implementable in hardware.
4
Sorting Networks (binary values)
inputs
outputs
1
0
0
0
0
0
Sorting Network
1
0
0
1
0
1
1
1
1
1
5
Comparator (2-sorter)
outputs
inputs
x
min(x, y)
C
y
max(x, y)
6
Comparator (2-sorter)
outputs
inputs
min(x, y)
x
max(x, y)
y
7
Comparison Network
8
Comparison Network
n / 2 comparisons per stage
9
Sorting Network
Any ideas?
10
Sorting Network
inputs
outputs
11
Insertion Sort Network
inputs
outputs
depth 2n 3
12
Batcher Sorting Network
Next Lecture
13
Batcher Sorting Network, n 4
14
Batcher Sorting Network, n 8
n 4
n 4
15
Lemma 1
Any subsequence of a sorted sequence is a sorted
sequence.
0
0
0
0
0
1
1
1
1
1
1
1
1
16
Lemma 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
17
Lemma 3
For two sorted sequences and
denotes the the number of 0s in
denotes the even subsequence of
denotes the odd subsequence of
18
Lemma 3
19
Lemma 3
For two sorted sequences and
(by Lemma 2)
(by Lemma 2)
20
Merge Network
21
Merge Network (pf.)
(by Lemma 1)
(by Lemma 1)
22
Merge Network (pf.)
23
Merge Network (pf.)
24
Merge Network (pf.)
0
0
0
0
1
0
1
0
0
0
0
1
0
1
1
1
25
Batcher Sorting Network
26
Batcher Sorting Network, n 4
Sort2
Sort2
27
Batcher Sorting Network, n 8
Sort4
Sort4
28
Sorting Networks
Batcher
AKS (Chvátal)
29
Sorting Arbitrary Numbers
outputs
inputs
min(x, y)
x
max(x, y)
y
x, y can be values from any linearly ordered
set, e.g., integers, reals, etc.
30
Integer Comparator
X, Y integers represented as m-bit binary
strings.
Idea use C(X,Y) to select the min and the max
of X and Y.
31
Sorting Arbitrary Numbers
sorted
32
Sorting Arbitrary Numbers
sorted
33
Sorting Arbitrary Numbers
not sorted
How can we verify if a network sorts all possible
input sequences?
34
Sorting Arbitrary Numbers
Try all possible 0/1 sequences.
35
Sorting Arbitrary Numbers
000
000
Try all possible 0/1 sequences.
36
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
Try all possible 0/1 sequences.
37
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
Try all possible 0/1 sequences.
38
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
Try all possible 0/1 sequences.
39
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
Try all possible 0/1 sequences.
40
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
101
011
Try all possible 0/1 sequences.
41
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
101
011
110
101
Try all possible 0/1 sequences.
42
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
101
011
110
101
111
111
Try all possible 0/1 sequences.
43
Sorting Arbitrary Numbers
44
Sorting Arbitrary Numbers
Try all possible 0/1 sequences.
45
Sorting Arbitrary Numbers
000
000
Try all possible 0/1 sequences.
46
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
Try all possible 0/1 sequences.
47
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
Try all possible 0/1 sequences.
48
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
Try all possible 0/1 sequences.
49
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
Try all possible 0/1 sequences.
50
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
101
011
Try all possible 0/1 sequences.
51
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
101
011
110
011
Try all possible 0/1 sequences.
52
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
101
011
110
011
111
111
Try all possible 0/1 sequences.
53
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
101
011
110
011
111
111
all sorted!
Try all possible 0/1 sequences.
54
Zero-One Principle
If a comparison network sorts all possible
sequences of 0s and 1s correctly, then it
sorts all sequences of arbitrary numbers
correctly.
55
Lemma
Given
For a monotonically increasing function f,
56
Lemma
Given
For a monotonically increasing function f,
57
Proof Lemma
58
Proof Lemma
59
Proof Lemma
f is monotonically increasing
60
Proof Lemma
f is monotonically increasing
61
Proof Lemma
f is monotonically increasing
62
Generalization
Given
63
Generalization
For a monotonically increasing function f,
(by induction)
64
Proof Zero-One Principle
65
Proof Zero-One Principle
66
Proof Zero-One Principle
Sorting Network
.
.
.
67
Proof Zero-One Principle
Sorting Network
.
.
.
Write a Comment
User Comments (0)
About PowerShow.com