Comparison Networks - PowerPoint PPT Presentation

1 / 56
About This Presentation
Title:

Comparison Networks

Description:

comparisons required to merge two arrays of size m/2. Order of ... Comparator (2-sorter) inputs. x. y. min(x, y) max(x, y) AON Implementation. outputs ... – PowerPoint PPT presentation

Number of Views:96
Avg rating:3.0/5.0
Slides: 57
Provided by: Jehosu1
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)
AON Implementation
outputs
inputs
x
min(x, y)
max(x, y)
y
7
Comparator (2-sorter)
outputs
inputs
min(x, y)
x
max(x, y)
y
8
Comparison Network
9
Comparison Network
n / 2 comparisons per stage
10
Sorting Network
Any ideas?
11
Sorting Network
inputs
outputs
12
Insertion Sort Network
inputs
outputs
depth 2n 3
13
Batcher Sorting Network
Next Lecture
14
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.
15
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.
16
Integer Comparator
X
min(X, Y)
Y
C(X, Y)
X
C(X, Y)
max(X, Y)
Y
17
Sorting Arbitrary Numbers
sorted
18
Sorting Arbitrary Numbers
sorted
19
Sorting Arbitrary Numbers
not sorted
How can we verify if a network sorts all possible
input sequences?
20
Sorting Arbitrary Numbers
Try all possible 0/1 sequences.
21
Sorting Arbitrary Numbers
000
000
Try all possible 0/1 sequences.
22
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
Try all possible 0/1 sequences.
23
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
Try all possible 0/1 sequences.
24
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
Try all possible 0/1 sequences.
25
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
Try all possible 0/1 sequences.
26
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
101
011
Try all possible 0/1 sequences.
27
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.
28
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.
29
Sorting Arbitrary Numbers
30
Sorting Arbitrary Numbers
Try all possible 0/1 sequences.
31
Sorting Arbitrary Numbers
000
000
Try all possible 0/1 sequences.
32
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
Try all possible 0/1 sequences.
33
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
Try all possible 0/1 sequences.
34
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
Try all possible 0/1 sequences.
35
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
Try all possible 0/1 sequences.
36
Sorting Arbitrary Numbers
inputs
outputs
000
000
001
001
010
001
011
011
100
001
101
011
Try all possible 0/1 sequences.
37
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.
38
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.
39
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.
40
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.
41
Lemma
Given
For a monotonically increasing function f,
42
Lemma
Given
For a monotonically increasing function f,
43
Proof Lemma
44
Proof Lemma
45
Proof Lemma
f is monotonically increasing
46
Proof Lemma
f is monotonically increasing
47
Proof Lemma
f is monotonically increasing
48
Generalization
Given
49
Generalization
For a monotonically increasing function f,
(by induction)
50
Proof Zero-One Principle
51
Proof Zero-One Principle
52
Proof Zero-One Principle
Sorting Network
.
.
.
53
Proof Zero-One Principle
Sorting Network
.
.
.
54
Implementing XOR
55
Implementing XOR
Sorting Network
56
Symmetric Functions
Sorting Network
Write a Comment
User Comments (0)
About PowerShow.com