1
00:00:20,150 --> 00:00:39,530
For today, we will be discussing on the Bitonic
sorting network. Now, same as did in the earlier
2
00:00:39,530 --> 00:00:42,120
case, here also we will first define
3
00:00:42,120 --> 00:00:49,120
what is bitonic sequence and then, we will
be discussing bitonic merge. Then, we will
4
00:00:58,339 --> 00:01:05,339
be discussing bitonic merging network and
5
00:01:06,340 --> 00:01:13,340
finally, will have bitonic sorting network.
So let a 1, a 2 be a sequence; a 1, a 2 to
6
00:01:51,850 --> 00:01:58,850
a n be a sequence. Now, the sequence
7
00:02:07,280 --> 00:02:14,280
is bitonic
8
00:02:14,430 --> 00:02:21,430
sequence, if there exists a j, such that,
either a 1 less than equal to a 2 n or by
9
00:03:16,239 --> 00:03:23,239
some cyclic shift, it satisfies 1.
The second sequence, bitonic sequence, if
10
00:03:32,450 --> 00:03:39,450
either a 1 less than equals to a 2 less than
equals to a n less than equals to a j and
11
00:03:47,230 --> 00:03:48,549
a j
12
00:03:48,549 --> 00:03:55,549
greater than equal to a j plus 1 is greater
than equals to a to n or by some cyclic shifts,
13
00:03:57,769 --> 00:04:04,769
which is this one. Now, for example, a
14
00:04:06,329 --> 00:04:13,329
sorted sequence is a bitonic sequence, say
why it is so? 1 2 3 4, so by cyclic shift,
15
00:04:20,239 --> 00:04:27,239
you can get 2 3 4 1 and which satisfies your
.
16
00:04:30,320 --> 00:04:37,320
Similarly that 4 3 2 1 is also a bitonic sequence.
This operator, even though I have written
17
00:04:49,680 --> 00:04:51,440
less than equals to, it can be greater
18
00:04:51,440 --> 00:04:58,409
than equals also. For a cyclic shift, it can
show that one. Another thing what I can tell
19
00:04:58,409 --> 00:05:05,409
is, a sequence of 2 elements is also a
20
00:05:15,039 --> 00:05:22,039
bitonic sequence. A sequence of two elements
is a bitonic sequence. So, definition is k
21
00:05:37,740 --> 00:05:44,740
s stage? No. Yes or no? If it is clear, then
22
00:05:59,240 --> 00:06:06,240
you can define a theorem. Let a 1, a 2 n be
a bitonic sequence of 2 n elements. Define
23
00:06:53,069 --> 00:06:58,680
two sequences b and e as, where d i is
24
00:06:58,680 --> 00:07:05,680
minimum of a i and a n plus i and e i is maximum
of e i and plus i. Then, d and e are bitonic
25
00:07:23,610 --> 00:07:30,610
sequences. The maximum of d is less
26
00:07:41,539 --> 00:07:48,539
than or equals to minimum of e. So statements
are clear?
27
00:07:59,770 --> 00:08:05,060
What we have obtained? We have obtained two
sequences d and e. d is obtained and the i
28
00:08:05,060 --> 00:08:09,689
th element d is obtained by taking the
29
00:08:09,689 --> 00:08:16,689
minimum of these two elements and e i is obtained
by taking the maximum of these two elements.
30
00:08:16,860 --> 00:08:18,379
Then, d is a bitonic sequence
31
00:08:18,379 --> 00:08:25,379
and e is also bitonic sequence and maximum
of d is less than equals to minimum of e.
32
00:08:28,310 --> 00:08:35,310
Now, in what, why this can be used for
33
00:08:35,719 --> 00:08:42,719
sorting? See, what it gives you that, from
this sequence, you are making two sequences,
34
00:08:46,090 --> 00:08:50,360
one is d and another one is e, right. From
35
00:08:50,360 --> 00:08:57,360
these two sequences, you make d and e. Now
this, recursively you do the bitonic merge
36
00:08:59,500 --> 00:09:02,090
on that, recursively you do the bitonic
37
00:09:02,090 --> 00:09:08,950
merge on this and you get another subsequent
like that. Every time you are achieving one
38
00:09:08,950 --> 00:09:11,980
thing, then these elements are smaller
39
00:09:11,980 --> 00:09:18,980
than these elements. These elements are the
smaller than these elements. So, by some recursive
40
00:09:19,060 --> 00:09:24,440
method, if you can sort this one,
41
00:09:24,440 --> 00:09:31,440
then the elements become a sorted one. Is
that ok? So, that is the idea. Now, how to
42
00:09:44,700 --> 00:09:49,380
prove this theorem?
43
00:09:49,380 --> 00:09:56,380
You have j equals to n and j less than n and
j greater than n. So, first thing is that,
44
00:10:13,200 --> 00:10:20,200
the cyclic shifts of the sequence a will affect
45
00:10:21,200 --> 00:10:28,200
both the d and e sequence similarly. Though
that I think the property of, these two property
46
00:10:29,580 --> 00:10:36,580
is, if you do the cyclic shifts, it will
47
00:10:36,880 --> 00:10:43,880
affect both the sequence d and e, right. Agreed?
But it will not affect these properties, right.
48
00:10:48,120 --> 00:10:55,120
So, we assume that for simplicity, we assume
the sequence is satisfying this type of characteristics.
49
00:11:04,900 --> 00:11:11,900
First assumption we are
50
00:11:12,030 --> 00:11:19,030
making. Now, second part is that, as he mentioned,
the j can be less than equals to n and j can
51
00:11:23,440 --> 00:11:27,340
be greater than n, right. Now, both
52
00:11:27,340 --> 00:11:34,340
the cases, if it is less than n, I can see
from this direction, that this j becomes greater
53
00:11:38,880 --> 00:11:45,320
than n. See, if I look from this side, agreed?
54
00:11:45,320 --> 00:11:52,320
Understood? If j less than n, if I see from
that side, j becomes greater than n and that
55
00:11:53,870 --> 00:11:55,620
also becomes bitonic sequence. Only the
56
00:11:55,620 --> 00:12:00,660
less than symbol becomes the greater than
symbol. Nothing else, right.
57
00:12:00,660 --> 00:12:07,660
So, without any loss of generating, we assume
that j is greater than n. If I can show this
58
00:12:13,330 --> 00:12:16,770
one, the other will also you can show. So,
59
00:12:16,770 --> 00:12:23,770
you assume that j is greater than n. So, you
have a 1 less than equals to a 2 less than
60
00:12:26,490 --> 00:12:33,490
equals to a n and less than equals to a j
plus
61
00:12:33,580 --> 00:12:40,580
1, a 2 n. Now, up to this we have done it.
This side is less than equal and greater than
62
00:13:01,520 --> 00:13:08,520
equal, right.
Now, assume that first case is, the two possibility
63
00:13:10,490 --> 00:13:17,490
cases, a n less than a 2 n and another case
could be a n greater than a 2 n. These
64
00:13:20,370 --> 00:13:27,370
are the two possibilities you have. This is
a n less than equals to a 2 n or a n greater
65
00:13:29,920 --> 00:13:33,940
than equal to a 2 n. Now, let us assume that
a
66
00:13:33,940 --> 00:13:40,940
n greater than equal to a 2 n; first case.
In that case, what is your d i and a i. d
67
00:13:51,480 --> 00:13:58,480
i is what? Minimum of a i and a plus i. So,
what is
68
00:14:04,350 --> 00:14:11,350
that a i and a plus i? Who is the minimum?
There is no ambiguity. Yes. So, I can write
69
00:14:13,300 --> 00:14:20,300
a i. What is a i? a n plus i. Agreed?
70
00:14:28,150 --> 00:14:35,150
Basically, this becomes your d sequence this
becomes your e sequence. Yes. So, this satisfies
71
00:14:44,510 --> 00:14:47,270
d 1 less than equals to d 2 less than
72
00:14:47,270 --> 00:14:54,270
equal to d n and you want, less than equals
to e 2 less than equals to; yes, because this
73
00:15:13,450 --> 00:15:17,990
side is less than equals to a j minus n and
74
00:15:17,990 --> 00:15:24,990
then, it is greater than. So, this is a bitonic
sequence. So, this is a bitonic sequence and
75
00:15:27,260 --> 00:15:33,630
this also is a bitonic sequence. For this
76
00:15:33,630 --> 00:15:40,630
case? This case? Here, a 1 less than equals
to a 2 less than equals to a n less than equals
77
00:15:45,440 --> 00:15:49,450
this greater than equals to and so on,
78
00:15:49,450 --> 00:15:56,450
right. Now, this element, this is your a i
and corresponding element is, may be here.
79
00:16:01,360 --> 00:16:08,360
Suppose corresponding element is here, a n
plus i, right. If it is the case, so this
80
00:16:09,030 --> 00:16:16,030
is less than less than less than, so this
is larger than
81
00:16:18,920 --> 00:16:24,420
this one, so minimum becomes d i and maximum
becomes here. Another possibility is that,
82
00:16:24,420 --> 00:16:31,420
your a i is here, a i plus 1, i is here, a
83
00:16:32,410 --> 00:16:39,410
and plus i is here. This element is less than
this element. This element is less than this
84
00:16:44,780 --> 00:16:48,050
element. This element is less than this
85
00:16:48,050 --> 00:16:55,050
element. So, this element is less than this
element. So, this becomes d i and this
become c i. Agreed? So, this becomes d sequence
86
00:17:03,530 --> 00:17:08,039
and this becomes e sequence and both of them
are bitonic sequences.
87
00:17:08,039 --> 00:17:15,039
Second part is, the maximum of this sequence
is d n and minimum of e sequence is what?
88
00:17:29,210 --> 00:17:36,210
Yes, minimum of e 1 or e n, right. Now,
89
00:17:40,310 --> 00:17:47,310
a 1 is either e 1. E 1 is what? e 1 is a n
plus 1 and e n is a 2 n. Agreed? Now, if it
90
00:18:04,770 --> 00:18:11,770
is the case, the d n is equal your a n. You
already
91
00:18:12,910 --> 00:18:19,910
have shown or from the definition that a n
is less than equal to n plus 1. From the definition
92
00:18:20,290 --> 00:18:23,780
itself because, j is somewhere and
93
00:18:23,780 --> 00:18:30,780
this is your n and this your j. This element
is always greater than this element and also
94
00:18:32,260 --> 00:18:37,420
by this case; this element is greater than
95
00:18:37,420 --> 00:18:44,420
this element. Agreed? So, d n is always less
than equal to e n.
96
00:18:55,310 --> 00:19:02,310
The next case is, is I can show for this case
also, and then your problem is solved. This
97
00:19:18,240 --> 00:19:25,240
is given to you. Now, I can always find
a
98
00:19:39,960 --> 00:19:46,960
k. In such a k, such that, a, I can always
find out
99
00:20:33,590 --> 00:20:40,590
the k, such that, a k minus n less than equals
to a k and a k minus n plus 1
100
00:20:41,110 --> 00:20:48,110
greater than equal to a k plus 1. Now, how
can I justify this? What I have found that
101
00:20:55,770 --> 00:21:00,630
a j minus n is less than equals to a j. This
is
102
00:21:00,630 --> 00:21:07,630
given to you. Agreed? a j minus 1 is less
than equals to a j. Because, from the definition
103
00:21:09,240 --> 00:21:16,240
of your bitonic sequence.
Now, you look for a j minus n plus 1, whether
104
00:21:19,460 --> 00:21:26,460
it is greater than a j plus 1 or not. Suppose
this is your j minus n and this your j. So,
105
00:21:30,540 --> 00:21:36,340
this satisfies the property. This is less
than equals to this. Now, whether this element
106
00:21:36,340 --> 00:21:41,010
is larger than this element and supposes it
is
107
00:21:41,010 --> 00:21:48,010
not. That means, this element is less than
equal to this element. You look for the next
108
00:21:49,800 --> 00:21:52,210
one, whether this element is larger than this
109
00:21:52,210 --> 00:21:59,210
element or not. Not. Suppose no. But, in that
case, think about this one, n minus 1 and
110
00:22:01,940 --> 00:22:05,760
2 n minus 1. So, this element is less than
111
00:22:05,760 --> 00:22:12,760
equals to this element, right. Because, you
are going one by one, so you got the last
112
00:22:16,180 --> 00:22:20,340
case a n minus 1 is less than equals to 2
n
113
00:22:20,340 --> 00:22:22,000
minus 1.
114
00:22:22,000 --> 00:22:29,000
But, from the assumption, a n is greater than
2 n. So, you will get one k satisfying this
115
00:22:30,300 --> 00:22:37,300
criteria. I am looking for the first . We
are
116
00:22:38,470 --> 00:22:45,470
looking for the smallest case satisfying this
criteria. Clear?
117
00:22:52,760 --> 00:22:59,760
If it is clear, then you got, this is n, this
is j, this is k, this is k minus n and this
118
00:23:11,030 --> 00:23:18,030
is 2 n. Now, here you the three cases. About
your a i
119
00:23:20,950 --> 00:23:27,950
a n k and plus i. i can be, n plus i can be
here, can be here and can be here. I can be
120
00:23:37,470 --> 00:23:41,950
here and I can be here. So, I can be here,
121
00:23:41,950 --> 00:23:47,960
here or here. Agreed? Now, suppose i is here.
First case is, i is here. So, what should
122
00:23:47,960 --> 00:23:49,890
be the; this is your n, this is your j, this
is
123
00:23:49,890 --> 00:23:56,890
your k and i
is here, n plus i and i is here. This is the
first case. Now, you tell me what should be
124
00:24:15,850 --> 00:24:21,179
d i and what should be your e i in
125
00:24:21,179 --> 00:24:28,179
this case? When i is n plus i is here. d i
is a i and e i is a n plus i. Also, in this
126
00:24:40,620 --> 00:24:47,620
zone, while I am, n plus i is in this zone,
can I write d
127
00:24:47,690 --> 00:24:50,470
i is less than equals to d 1 plus 1?
128
00:24:50,470 --> 00:24:57,470
e i will also be e i plus 1. I can right this,
i less then equals to this number. Not crossing
129
00:25:10,270 --> 00:25:17,000
this number. I can write i plus 1 less than
130
00:25:17,000 --> 00:25:24,000
equals to j minus n. That condition is proved.
So, that, up to this point, this point I am
131
00:25:32,530 --> 00:25:37,130
talking about. Is it ok? Yes. Now, let us
take
132
00:25:37,130 --> 00:25:44,130
the second case, 2 nm this is your j, this
is your k and this is your k minus n and n
133
00:26:02,160 --> 00:26:09,160
plus i is lying here. Now, can you tell me,
when
134
00:26:18,360 --> 00:26:25,360
n plus i is lying, what is your d i and what
is your e i? So, if you shown that, if you
135
00:26:41,929 --> 00:26:48,929
are writing like that, a n plus i is greater
than
136
00:26:49,840 --> 00:26:56,840
equal to, a n plus i plus 1 greater than equal
to a k. a k is greater than equals to a k
137
00:27:04,290 --> 00:27:11,290
minus
n greater than greater than equal to a i.
138
00:27:14,090 --> 00:27:18,559
Basically, I am going from this direction
to this and then, from this to this. I have
139
00:27:18,559 --> 00:27:25,559
used this property, right. So, you are writing
d i
140
00:27:31,140 --> 00:27:38,140
is your a i and e i is a i plus i and what
is the relationship between d i and d i plus
141
00:27:41,929 --> 00:27:48,929
1 here? d i is and what is d i? So, you got
the
142
00:27:59,760 --> 00:28:00,850
second thing.
143
00:28:00,850 --> 00:28:07,850
Now, I need the third case. Third case is,
here j, here k, k minus n and your i is lying
144
00:28:26,610 --> 00:28:33,610
here and i is here.
145
00:28:33,670 --> 00:28:40,670
Now, you see, here I can write a i plus n
is less than equals to a i plus n minus 1
146
00:28:48,130 --> 00:28:55,130
a k plus 1 less than a k minus n plus 1.
147
00:29:01,730 --> 00:29:08,730
So, it is here and less than equals to a k
minus n plus 2 a i. Agreed?
148
00:29:18,710 --> 00:29:25,710
Basically what I am doing, I am moving from
this side to this side. Here, it is k plus
149
00:29:26,890 --> 00:29:32,450
1 and then, moving from this to this. From
this
150
00:29:32,450 --> 00:29:39,450
side to this k plus 1 and I know the relationship
between k plus 1 k minus 1 and plus 1.
151
00:29:41,390 --> 00:29:48,390
I am moving from this to this. Is it ok? If
it is ok, then here I get this relation. From
152
00:29:49,190 --> 00:29:56,190
here, I get d i and e i. What you get? a n
plus i
153
00:30:02,370 --> 00:30:09,370
and here a i, right. What is the relationship
between d i and d i plus 1? e i and e i plus
154
00:30:15,580 --> 00:30:22,580
1? d i is greater than equals to, yes, because
155
00:30:39,000 --> 00:30:43,730
a i plus 1 will be here.
156
00:30:43,730 --> 00:30:50,730
So, this is greater than this and e i? e i?
a i? Why? See, a i is coming this side, right.
157
00:31:09,750 --> 00:31:14,100
a i is this one and a i plus 1 is this. So,
a i is
158
00:31:14,100 --> 00:31:21,100
this. Is it not? This is a i and this is a
i plus 1. So, if I combine all this, what
159
00:31:41,980 --> 00:31:48,980
I get? First, let us consider the d 1 case.
You get d 1
160
00:31:53,400 --> 00:32:00,400
less than equals to d 2 less than equals to
d j minus n
less than equals to d j minus n plus 1 d k
161
00:32:43,870 --> 00:32:50,510
minus n. Then, I do not know the
162
00:32:50,510 --> 00:32:57,510
relationship here, d k minus n plus 1 d n,
right. I do not know the relationship here,
163
00:33:03,260 --> 00:33:07,120
because here it takes up to d k minus n and
164
00:33:07,120 --> 00:33:14,120
this side, and I am starting from d k plus
n minus 1. I do not know that relation or
165
00:33:14,169 --> 00:33:16,660
what would be the relation. So, the relation
we
166
00:33:16,660 --> 00:33:23,660
will find out what is the relation. Up to
this is known to you. What about e 1? 3 1
167
00:33:28,820 --> 00:33:35,820
is less than equals to e 2 less than or equal
to e j
168
00:33:37,309 --> 00:33:44,309
minus n. Then, you have greater than equals
to e j minus n plus 1 greater than equal to
169
00:33:50,040 --> 00:33:54,080
up to e k minus n. I do not know the
170
00:33:54,080 --> 00:34:01,080
relationship between e k minus n and e k minus
n plus 1. Then, I know this relation.
171
00:34:03,049 --> 00:34:10,049
Do you know any relationship between e 1 and
e n? What is the relationship between e 1
172
00:34:15,510 --> 00:34:22,510
and e n? What is your e 1? e 1 is; what
173
00:34:23,540 --> 00:34:30,540
is e 1? a n plus 1. e 1 is a n plus 1. What
is e n? e n is where? If it is, do you know
174
00:34:55,979 --> 00:35:02,979
any relationship between e 1 and e n? So,
I can
175
00:35:06,720 --> 00:35:13,720
write e n is less, sorry e n is less than
e 1. Agreed? Yes. Now, in that case, first
176
00:35:39,420 --> 00:35:43,099
you tell me, if I know how this is, now I
know the
177
00:35:43,099 --> 00:35:50,099
relation here. e n less than equal to e 1.
So, think about this one? Can I tell this
178
00:35:50,880 --> 00:35:55,420
is a bitonic sequence irrespective of whatever
is
179
00:35:55,420 --> 00:36:02,420
the relationship between these two?
Suppose it is less than equals to, then it
180
00:36:02,819 --> 00:36:09,819
is a bitonic sequence. If it is greater than
or equal to, then also it is a bitonic sequence.
181
00:36:12,519 --> 00:36:13,309
So,
182
00:36:13,309 --> 00:36:15,450
this is a bitonic sequence. What about this
one? This is also bitonic sequence, because
183
00:36:15,450 --> 00:36:19,180
by cyclic shift, I can find out this is less
184
00:36:19,180 --> 00:36:26,180
than equals to e 1 less than equals to up
to less than equals to e j minus n, right.
185
00:36:27,930 --> 00:36:31,729
Then, I can get e j minus n plus 1 greater
than
186
00:36:31,729 --> 00:36:35,749
greater than greater than e k minus n. Whatever
is the relationship between this, again less
187
00:36:35,749 --> 00:36:37,390
than equal to this, so it becomes a
188
00:36:37,390 --> 00:36:44,319
bitonic sequence. So, the first point is that,
d and e they are bitonic sequence. That is
189
00:36:44,319 --> 00:36:44,999
true.
190
00:36:44,999 --> 00:36:51,999
Now, what you have to show? That maximum of
d is less than equals to minimum of d. Now,
191
00:36:52,259 --> 00:36:54,460
suppose you have a bitonic
192
00:36:54,460 --> 00:37:01,460
sequence, a 1 a 2 a 3 a 4 a n, right. What
should be your network? Network will look
193
00:37:10,430 --> 00:37:15,349
like, that you have comparator n by 2
194
00:37:15,349 --> 00:37:22,349
comparator and you have a n by 2 plus 1 n
by 2 plus and 2 and so on. So, it goes like
195
00:37:37,029 --> 00:37:44,029
this. So, this is a bitonic system. This is
a
196
00:37:47,589 --> 00:37:54,589
bitonic system. So, a i has to be compared
with a n plus i. Same thing we did and then,
197
00:37:55,890 --> 00:38:02,890
you get n by 2 bitonic merging network
198
00:38:10,729 --> 00:38:17,729
and you have n by 2 bitonic merging network,
right. So, you get here basically d 1 d 2
199
00:38:41,049 --> 00:38:48,049
d n by 2 and you get e 1 e 2 e n by 2. Then,
200
00:38:53,460 --> 00:39:00,460
recursively if you call, you get c 1 c 2 c
3 c n by 2 plus 1 c n. So, you have one comparator
201
00:39:11,720 --> 00:39:14,739
and a i is compared with a n by 2 plus
202
00:39:14,739 --> 00:39:19,769
i and smaller elements you keep it in this
sequence and larger elements, bring it to
203
00:39:19,769 --> 00:39:23,619
e sequence and then, this becomes a bitonic
204
00:39:23,619 --> 00:39:29,339
sequence. This become a bitonic sequence recursively
you do it and then, finally you get sorted
205
00:39:29,339 --> 00:39:32,849
sequence in this side and sorted
206
00:39:32,849 --> 00:39:35,769
sequence in this side, right.
207
00:39:35,769 --> 00:39:42,769
If it is the case, then how many comparators
you need? Number of component is n by 2 plus
208
00:39:52,609 --> 00:39:59,609
c n by 2 2 times. If n is greater than
209
00:40:04,049 --> 00:40:11,049
2 and one is n equal to 2. n by 2 plus 2 n
by 2, if n is greater than 2 and one, if n
210
00:40:21,670 --> 00:40:25,680
is equal to 2. Because, you have two elements
211
00:40:25,680 --> 00:40:32,680
and you have one comparator. The number of
steps, parallel steps you need, t n is equals
212
00:40:33,979 --> 00:40:40,979
to 1 plus t n by 2, if n is greater than 2
213
00:40:44,140 --> 00:40:51,140
and one is n equal to 2, right. So, there
is one and then, whatever time you need. Now,
214
00:41:01,410 --> 00:41:07,529
assume n is equal to 2 k.
215
00:41:07,529 --> 00:41:14,529
So, you can easily solved t n, because, this
becomes t 2 and t 2 is also 1, so it is k,
216
00:41:45,849 --> 00:41:52,690
which is your log n. Now, if I have to compute,
217
00:41:52,690 --> 00:41:59,690
c n is equal to 2 times c n by 2 square plus
n by 2, so you get 2 square c n by 2 square
218
00:42:15,529 --> 00:42:22,529
plus n by 2 plus n by 2. Then, 2 to the
219
00:42:25,519 --> 00:42:32,519
power k minus 1 c n by 2 k minus 1 plus n
by 2. So, 2 to the power k minus 1, because
220
00:42:48,089 --> 00:42:55,089
c 2 is 1, so you get k minus 1 n by 2 and
221
00:43:00,619 --> 00:43:07,619
this is also 1 n by 2, right. So, you get
k n by 2. That is, n by 2 log n.
222
00:43:11,989 --> 00:43:18,989
So, you get c n is equals to n by 2 log n.
T n equals to log n and cost is n by 2 log
223
00:43:38,130 --> 00:43:44,339
square n. So, you merge a bitonic sequence
into
224
00:43:44,339 --> 00:43:51,339
a sorted sequence. One thing you the absorb
that, you must have a bitonic sequence to
225
00:43:52,369 --> 00:43:54,609
merge this one. So, the sequence must be
226
00:43:54,609 --> 00:43:56,180
a bitonic sequence.
227
00:43:56,180 --> 00:44:03,180
If I have to think that how can I use this
idea to sort n arbitrary element. So, let
228
00:44:07,150 --> 00:44:14,150
us 8 elements, 7 1 2 4 3 6 5 8. Yes. Idea
is that
229
00:44:25,859 --> 00:44:31,589
you use the alongs of the two elements are
always bitonic and then, you merge it. You
230
00:44:31,589 --> 00:44:35,660
must get it, after merge, you get the larger
231
00:44:35,660 --> 00:44:42,660
bitonic sequence. So, basically it is nothing
but, the idea is that, this one you may make
232
00:44:49,799 --> 00:44:52,460
increasing sequence and this you get in
233
00:44:52,460 --> 00:44:57,900
decreasing sequence, so that you get, at the
end of this, you get a bitonic sequence of
234
00:44:57,900 --> 00:45:02,719
larger size. So, here you will be getting
1 7
235
00:45:02,719 --> 00:45:09,719
4 2 3 6 8 5. See, you observe, now this is
the bitonic sequence and this is another bitonic
236
00:45:13,849 --> 00:45:17,440
sequence. You can get this in sorted
237
00:45:17,440 --> 00:45:23,390
sequence in increasing order. This should
be in increasing order and this should be
238
00:45:23,390 --> 00:45:26,789
decreasing order, so that this becomes another
239
00:45:26,789 --> 00:45:31,950
bitonic sequence.
So, in order to do that, this should be in
240
00:45:31,950 --> 00:45:38,950
increasing order. You first compare, a i is
to be compared with n plus i. So, you get
241
00:45:47,369 --> 00:45:48,430
here
242
00:45:48,430 --> 00:45:55,430
14 2 7. Now, this becomes a bitonic sequence
and this becomes a bitonic sequence, so you
243
00:45:59,559 --> 00:46:02,789
get a sorted sequence here. Similarly,
244
00:46:02,789 --> 00:46:09,789
is the case here. So, compare these two and
you get 8, you get 3, you get 6, you get 5
245
00:46:17,680 --> 00:46:22,119
and then, you compare these two. You get 8
246
00:46:22,119 --> 00:46:29,119
6 5 3. So, this becomes another bitonic sequence.
You observe, at the end of
this stage, you get a bitonic sequence of
247
00:46:39,180 --> 00:46:41,309
size a. Now,
248
00:46:41,309 --> 00:46:47,309
you have to make it a sorted sequence. So,
a i has to be compared. That is, this has
249
00:46:47,309 --> 00:46:48,839
to be compared, this has to be compared with
250
00:46:48,839 --> 00:46:55,839
this and this has to be compared with this
and this has to be compared with this, right.
251
00:46:57,299 --> 00:47:01,349
After doing that, so if I compare 1 with 8,
252
00:47:01,349 --> 00:47:08,349
you will get 1 and here 8, 2 with 6, 2 here,
6 here and 4 with 5, 4 here and 5 here, 3
253
00:47:14,380 --> 00:47:19,140
with 7, 3 here and 7 here. Now, the problem
254
00:47:19,140 --> 00:47:26,089
is, this is a bitonic sequence and this is
another bitonic sequence and all these elements
255
00:47:26,089 --> 00:47:29,279
are larger than these elements, right.
256
00:47:29,279 --> 00:47:36,279
Because, d i is smaller than e i. So, you
now compare this with this, this with this,
257
00:47:37,890 --> 00:47:43,920
this with this and this with this, you get
here 1 4
258
00:47:43,920 --> 00:47:50,920
2 3 5 8 6 7. Then, you compare with this,
this 1 2 3 4 5 6 7 8. Now, how many parallel
259
00:48:09,619 --> 00:48:11,950
steps you need? Parallel phases you need?
260
00:48:11,950 --> 00:48:17,769
This is phase 1, phase 2, and phase 3.
261
00:48:17,769 --> 00:48:24,769
So, if you have a bitonic sequence, if you
have the sequence of 8 elements, there will
262
00:48:27,109 --> 00:48:32,739
be 3 phases. That means, you have the log
n
263
00:48:32,739 --> 00:48:39,739
phases. Agreed? At the i th phase, you have
several parts, each of size 2 to the power
264
00:48:47,549 --> 00:48:52,380
i bitonic sequence. At the i th phase, there
265
00:48:52,380 --> 00:48:59,380
are log n phases. Agreed? At the i th phase,
there are several bitonic sequence each of
266
00:49:14,799 --> 00:49:21,799
size 2 to the power i. Now, can you tell me
267
00:49:22,619 --> 00:49:29,619
what is this value of several? n by 2 to the
power i.
268
00:49:47,209 --> 00:49:54,209
That is, 2 to the power k minus i. n is 2
to the power k, right. So, that many parts
269
00:50:00,299 --> 00:50:04,130
are there. In this case, second phase, you
have 2
270
00:50:04,130 --> 00:50:11,130
to the power i, 2 to the power 2 4 and there
are two such cases. So, it is 2 to the power
271
00:50:13,799 --> 00:50:18,319
k minus I bitonic subsequences each of
272
00:50:18,319 --> 00:50:25,319
size 2 to the power i. Agreed? Now, if it
is the case, can we find out
total number of parallel steps
and number of comparators
and
273
00:50:54,859 --> 00:50:56,059
then, type of comparators.
274
00:50:56,059 --> 00:51:03,059
You need to know these three things. You observed
that, here it is not like ordinary that the
275
00:51:13,799 --> 00:51:16,289
comparator has two inputs and the
276
00:51:16,289 --> 00:51:23,059
output is the, first output is the minimum
and second output is maximum. Here, it is
277
00:51:23,059 --> 00:51:25,700
depending upon the phase, whether it is in
278
00:51:25,700 --> 00:51:32,269
increasing order or decreasing order, right.
So, the two types of comparators you will
279
00:51:32,269 --> 00:51:39,269
be using a and b min. Actually, it is not
very
280
00:52:08,059 --> 00:52:15,059
difficult to implement. The first one, if
you implement only the , you have to change
281
00:52:15,109 --> 00:52:18,079
to give you the maximum output in the top
282
00:52:18,079 --> 00:52:25,079
and minimum output in the final. This is not
a big thing. Only thing is that, you have
283
00:52:26,369 --> 00:52:29,589
to, phase wise you have to keep it in mind
284
00:52:29,589 --> 00:52:33,519
which comparator you will be going to use,
right.
285
00:52:33,519 --> 00:52:39,749
In the first phase, alternatively high low
high low high low and here, in second phase,
286
00:52:39,749 --> 00:52:44,609
it is low low high high and then, this is
low
287
00:52:44,609 --> 00:52:51,609
low low low. That is the only thing, right.
So, this, easily you can do this. The type
288
00:52:54,119 --> 00:52:56,430
of comparators you will be using that is known
289
00:52:56,430 --> 00:53:03,430
to you. Now, what about these two? Number
of parallel steps, first phase, one parallel
290
00:53:07,950 --> 00:53:12,559
step and second phase, how many parallel
291
00:53:12,559 --> 00:53:14,219
steps? right
292
00:53:14,219 --> 00:53:21,130
How many parallel steps? This is one, this
is one and this is another one. Agreed? Third
293
00:53:21,130 --> 00:53:28,130
one is what? How many parallel steps?
294
00:53:30,670 --> 00:53:37,670
This is one. This number of parallel steps
you have already obtained. The third step,
295
00:53:41,430 --> 00:53:45,170
you have 2 to the power 3 elements and they
296
00:53:45,170 --> 00:53:52,170
are bitonic sequence and you are making three
parallel steps and the i th is you are making
297
00:53:52,829 --> 00:53:59,829
i parallel steps. Agreed? So, i parallel
298
00:54:00,329 --> 00:54:07,329
steps at the i th stage. How many i? i is
1 to log n. So, it is log n log n plus 1,
299
00:54:17,049 --> 00:54:21,549
which is order log square n. So, number of
parallel
300
00:54:21,549 --> 00:54:28,549
steps is order log square n. Now, can you
tell me how to find out number of comparators
301
00:54:32,390 --> 00:54:39,390
at the i th stage? At the i th stage, how
302
00:54:41,890 --> 00:54:48,890
many parts are there? 2 to the power i 2 to
the n minus i, that many sub parts are there.
303
00:54:49,229 --> 00:54:56,229
In the i th stage, 2 to the power n minus
i sub parts are there. This is a bitonic sequence
304
00:54:57,910 --> 00:55:04,910
is size to the power i. Agreed? So, this is
2
305
00:55:07,130 --> 00:55:14,130
to the power i minus 1 i. Summation over.
i equals 1 to log n. There are n minus 2 to
306
00:55:24,499 --> 00:55:26,959
the power n minus i sub parts are there. Each
307
00:55:26,959 --> 00:55:33,959
part is a size of 2 to the power i, which
is a bitonic sequence. To do that, you need
308
00:55:34,059 --> 00:55:38,069
the number of comparators i into 2 to the
309
00:55:38,069 --> 00:55:45,009
power i minus 1, which has come from here.
2 to the power, yes, this k minus, yes, this
310
00:55:45,009 --> 00:55:52,009
2 to the power k minus i, yes. Agreed?
If it is that, this becomes summation over
311
00:55:59,999 --> 00:56:06,999
1 log n 2 to the power k minus 1 i 2 to the
power k minus 1 goes out and it is submission
312
00:56:14,190 --> 00:56:21,190
over i, which is again log of n log of n plus
1 upon 2, which is order n log square n. So,
313
00:56:36,249 --> 00:56:42,160
you can write number of compotators you
314
00:56:42,160 --> 00:56:49,160
need order n log square n and number of parallel
steps is order log square n.
315
00:56:55,099 --> 00:57:02,099
So, for sorting n elements, you need, the
cost is order n log to the power 4 n.
316
00:57:06,309 --> 00:57:13,309
So, it is also far away from the cost of optimizing
point of the . What should be the basic unit
317
00:57:21,440 --> 00:57:26,199
of bitonic? Basically, you will need,
318
00:57:26,199 --> 00:57:33,199
suppose you have 4 elements, which forms a
bitonic sequence. That is, 2 elements and
319
00:57:53,259 --> 00:58:00,259
2 elements, you need to give the sorting
320
00:58:05,869 --> 00:58:12,869
sequence. If you have 4 elements, which forms
a bitonic sequence and the structure is like
321
00:58:13,049 --> 00:58:16,119
that. Now, if you have to combine
322
00:58:16,119 --> 00:58:21,869
both the things for obtaining a sorted, suppose
it is an arbitrary element and you want to
323
00:58:21,869 --> 00:58:24,779
have the sorting sequence, you can
324
00:58:24,779 --> 00:58:31,779
easily find out that. Suppose this is arbitrary
one, a 1 a 2 a 3 a 4. So, first you make,
325
00:58:36,499 --> 00:58:41,940
this is low and this is high. This is high
and
326
00:58:41,940 --> 00:58:48,940
this is low. Now, this becomes a bitonic sequence.
Now, in the second phase, you get low low
327
00:59:02,779 --> 00:59:09,779
high. So you will get the sorted sequence,
right. Now, if you observe or if you compare
328
00:59:23,579 --> 00:59:30,579
this with odd even merge techniques, you will
find what? If the same number of competitor
329
00:59:35,599 --> 00:59:42,599
sure order wise it may be same, but,
330
00:59:54,160 --> 01:00:01,160
you are using more number of comparators.
Because, if you observe that was, if you have
331
01:00:01,229 --> 01:00:04,579
odd even merge, you first you do odd
332
01:00:04,579 --> 01:00:11,579
even merge plus n minus 1. You do not need
any comparators here. You need, right, so
333
01:00:12,670 --> 01:00:14,799
number of comparators are increasing.
334
01:00:14,799 --> 01:00:21,799
Cost wise it is the same order. There is no
problem. Moreover, in bitonic merge, you have
335
01:00:22,380 --> 01:00:25,369
to keep track of odd even and you have
336
01:00:25,369 --> 01:00:32,369
to keep low high high low, all those information,
which you do not have to keep for odd even.
337
01:00:38,499 --> 01:00:40,440
So, this is all about your bitonic
338
01:00:40,440 --> 01:00:47,440
sequence. Now, any questions on this? If there
is not, I do not want to start the sorting
339
01:00:57,349 --> 01:01:03,859
algorithm.
It is a bitonic sequence. You will realize,
340
01:01:03,859 --> 01:01:10,859
for network model, we will discuss how efficiently
you can use the bitonic sequence to
341
01:01:11,940 --> 01:01:18,940
sort an element, which may not be possible
for odd even merge which is present on network
342
01:01:23,190 --> 01:01:30,190
models. We will discuss it. Yes, not
343
01:01:32,390 --> 01:01:39,390
only that, number of comparators is greater,
it is also you have to keep track of how many
344
01:01:39,749 --> 01:01:42,609
low high and how many high low
345
01:01:42,609 --> 01:01:49,190
comparators you need, right. Did you, could
you go through the or could you get the time
346
01:01:49,190 --> 01:01:56,190
to open the book and go to volume 3.
347
01:02:03,979 --> 01:02:10,709
No. Is there anybody? No. I asked minimum
sorting network, minimum number of comparators
348
01:02:10,709 --> 01:02:15,140
that type of chapter is in the
349
01:02:15,140 --> 01:02:22,140
book, volume 3, chapter 3 5.4 or something
like that. You please go through that. Sorting
350
01:02:25,499 --> 01:02:31,130
network discussion is there. You can
351
01:02:31,130 --> 01:02:36,219
you use any one of them. See, here you observe
what we need. We started with two elements
352
01:02:36,219 --> 01:02:40,019
and two elements. Instead of that, if
353
01:02:40,019 --> 01:02:47,019
I use 5 elements, whether it can achieve the
goal of sorting efficiently or not. If it
354
01:02:48,559 --> 01:02:52,349
is, then, how much? That type of things you
can
355
01:02:52,349 --> 01:02:59,349
get. Because, what we observed, that if the number of element is odd, then number of comparators
356
01:02:59,349 --> 01:03:01,800
take less to sort.