1
00:00:16,059 --> 00:00:37,070
Two-dimensional mesh connected computer, right
and this algorithm is based on Bitonic sorting
2
00:00:37,070 --> 00:00:44,070
technique. I hope you have not
3
00:00:44,839 --> 00:00:51,839
yet forgotten what is Bitonic sorting. So,
the algorithm is a Bitonic sorting technique
4
00:00:52,030 --> 00:00:55,140
and that has been implemented on two
5
00:00:55,140 --> 00:01:01,439
dimensional MCC. Just like this. Like the
Bitonic sort, what it does? You remember in
6
00:01:01,439 --> 00:01:06,280
the Bitonic merge, what will you do? That
i
7
00:01:06,280 --> 00:01:13,280
is compared with a n plus i.
The smaller one you keep it one side and larger
8
00:01:13,420 --> 00:01:20,420
one goes to the another side and then, go
both the sequence is Bitonic sequence
9
00:01:21,280 --> 00:01:28,280
and they can recursively solve them. That
is the idea. Now here, we show that a mesh
10
00:01:29,659 --> 00:01:36,659
is having n cross n, crosses, that is n
11
00:01:38,179 --> 00:01:45,179
processors and each process contains one element.
Each process has at least three registers,
12
00:02:27,709 --> 00:02:29,709
R r, R s and R t. So, these are the
13
00:02:29,709 --> 00:02:36,709
registers. I mean, memory locations it needs.
This is storage register; this is a say temp
14
00:02:53,079 --> 00:02:59,319
and this is called routing. So, in order to
15
00:02:59,319 --> 00:03:06,319
transfer one data from one processor to another
processor, the data must be in this register,
16
00:03:14,370 --> 00:03:17,000
right.
17
00:03:17,000 --> 00:03:24,000
Now, each processor is capable of performing
three types of operation. One is routing operations
18
00:03:42,780 --> 00:03:49,780
between R r with that of its
19
00:04:16,820 --> 00:04:23,820
neighbour. Compare exchange between two registers
on same processor. Compare exchange means
20
00:04:55,090 --> 00:04:58,120
that content of R r and
21
00:04:58,120 --> 00:05:05,120
content of R s will be compared and if it
is, the winner will be kept in R s and loser
22
00:05:05,710 --> 00:05:08,539
will be kept in R r. Who is the winner?
23
00:05:08,539 --> 00:05:15,539
Suppose, in the case of increasing order,
minimum is the winner and in the case of decreasing
24
00:05:21,270 --> 00:05:28,270
order, maximum will be the winner.
Then, another operation is only exchange operations
25
00:05:30,470 --> 00:05:37,470
between two registers. So, these are the three
operations the processors can
26
00:05:43,770 --> 00:05:50,770
perform. The time needs, I have already told
about R r. So, let us put some other symbol.
27
00:05:56,490 --> 00:06:03,180
Let us put t r, t c and t e. So, the time
28
00:06:03,180 --> 00:06:10,110
need for one routing takes t r time and t
c is the time need for compare exchange and
29
00:06:10,110 --> 00:06:16,720
t e is the only exchange. This is the time.
30
00:06:16,720 --> 00:06:23,720
So, up to this the definition is clear? So,
in case you need, it is clear?
31
00:06:35,400 --> 00:06:42,400
Time means, say p i has data a in R r register
and b is in R s register. So, if you perform
32
00:07:00,539 --> 00:07:05,909
exchange operation, what will happen?
33
00:07:05,909 --> 00:07:12,909
That b will be here, a will be here, b is
in R r register and a is in R s register and
34
00:07:15,090 --> 00:07:22,090
to do this, you need t e. Is it ok? Now, before
we
35
00:07:26,599 --> 00:07:33,409
start about this algorithm, how will we do
it, let us first recollect the Bitonic sorting
36
00:07:33,409 --> 00:07:40,409
technique. What you did a 1, a 2, a 3, a 4,
a 5,
37
00:07:42,750 --> 00:07:49,750
a 6, a 7, let us take a 8 here. These are
the 8 elements you have and every time you
38
00:07:50,460 --> 00:07:53,770
have to arrange in such a way that it should
39
00:07:53,770 --> 00:08:00,770
becomes a Bitonic sequence for the next step
and also it is known to you that 2 sequence
40
00:08:03,789 --> 00:08:08,129
with 2 elements is always a Bitonic
41
00:08:08,129 --> 00:08:12,460
sequence.
So, this is one Bitonic sequence and this
42
00:08:12,460 --> 00:08:18,560
is another Bitonic sequence. There are 4 Bitonic
sequences. So, you have to arrange in
43
00:08:18,560 --> 00:08:23,490
such a way that next time you get a Bitonic
sequence. So, you have to have some idea that
44
00:08:23,490 --> 00:08:27,400
how to create it. So, if I do this is
45
00:08:27,400 --> 00:08:31,740
increasing order; this is decreasing order,
then this whole sequence becomes Bitonic sequence.
46
00:08:31,740 --> 00:08:38,740
Similarly, is the case. Now, you get
47
00:08:40,729 --> 00:08:47,729
2 Bitonic sequences. This is one Bitonic sequence
and this is the another one. So, you arrange
48
00:08:48,399 --> 00:08:54,269
it in the second phase and then,
49
00:08:54,269 --> 00:09:01,269
finally you get this one, right. This is the
strategy. Now, in case of two dimensional
50
00:09:14,110 --> 00:09:21,110
mesh, suppose we have 16 elements. These
51
00:09:25,790 --> 00:09:32,790
elements are here and this processor is connected
with these 4 neighbours, right, at least,
52
00:09:44,279 --> 00:09:48,480
at most. So, it consist of, you remember
53
00:09:48,480 --> 00:09:55,480
that it consists of 6 steps and there it consists
of 4 parallel phase. First phase, you will
54
00:09:57,740 --> 00:10:02,610
be making a Bitonic sequence of size, you
55
00:10:02,610 --> 00:10:09,610
have Bitonic sequence of size 2. If you consider,
this is one size 2, 1, 1, 1, 1, 1, 1, like
56
00:10:09,870 --> 00:10:16,870
that 8 such Bitonic sizes you have.
How do you know that there is a class going
57
00:10:23,430 --> 00:10:30,430
on? There was a telephone or message? Guessing?
After 40 minutes, you cannot
58
00:10:45,050 --> 00:10:50,050
guess. Do not worry. Just random? It is difficult.
For those of you who joined late, let me tell
59
00:10:50,050 --> 00:10:51,170
you, today we are discussing on
60
00:10:51,170 --> 00:10:58,170
sorting and the model is two dimensional mesh.
Here, we have assumed that there are n cross
61
00:10:58,399 --> 00:10:59,920
n processors and each processor
62
00:10:59,920 --> 00:11:04,490
contains 1 element and each processor has
at least 3 registers or 3 memory locations.
63
00:11:04,490 --> 00:11:11,490
One is R r and another is R s and R t. R r
is
64
00:11:15,970 --> 00:11:22,970
the routing register, R s is the storage register
and R t is a temporary storage register. The
65
00:11:23,829 --> 00:11:27,820
result, the final result would be is R s
66
00:11:27,820 --> 00:11:33,500
register. Now, each processor is capable of
doing 3 types of operations, routing operations
67
00:11:33,500 --> 00:11:35,680
between two orders; order of processor
68
00:11:35,680 --> 00:11:42,680
i and order of processor j. But processor
j must be a neighbour and time needs for that
69
00:11:47,089 --> 00:11:50,260
is t r. Compare exchange operation
70
00:11:50,260 --> 00:11:57,260
between two registers of a processor and it
checks order, time order t c and similarly,
71
00:11:57,529 --> 00:11:59,880
exchange operation takes order t e time.
72
00:11:59,880 --> 00:12:06,880
This is the example what I gave by exchange
operations.
73
00:12:07,279 --> 00:12:14,279
Then, we discussed about the strategy followed
in the Bitonic sorting technique for 8 elements.
74
00:12:17,019 --> 00:12:18,730
Finally, we are discussing about
75
00:12:18,730 --> 00:12:25,730
that how we are going to use it on two dimensional
mesh, where you have 4 cross 4 mesh and 16
76
00:12:28,070 --> 00:12:30,540
elements. Now, if you observe
77
00:12:30,540 --> 00:12:36,399
this 16 elements, you can think that it can
form 8 Bitonic sequences and each of size
78
00:12:36,399 --> 00:12:40,209
2. Now, you have to go to the next level,
79
00:12:40,209 --> 00:12:47,209
which will give you 4 Bitonic sequences of
size 4, right. So, you have to arrange in
80
00:12:48,060 --> 00:12:50,800
such a way that one is in increasing order
and
81
00:12:50,800 --> 00:12:56,050
other is in decreasing order, right. One possible
way could be that, you put it in increasing
82
00:12:56,050 --> 00:12:58,260
order and you put in decreasing order,
83
00:12:58,260 --> 00:13:03,300
so you get a Bitonic sequence of size 4, this
side, this side, and this side and so on.
84
00:13:03,300 --> 00:13:09,600
In that process, you find little bit of difficulty.
What we do is, we arrange this in increasing
85
00:13:09,600 --> 00:13:12,480
order and this in decreasing order and
86
00:13:12,480 --> 00:13:19,480
this forms a Bitonic sequence. So, in the
first phase, you arrange the data in such
87
00:13:37,610 --> 00:13:41,760
a way that you get 4 Bitonic sequences each
of
88
00:13:41,760 --> 00:13:48,760
size 4. In the second phase, now you have
to arrange the data in such a way that you
89
00:14:00,290 --> 00:14:05,339
get 2 Bitonic sequences of size 4, each of
90
00:14:05,339 --> 00:14:12,339
size 8. So, you arrange the data in increasing
order and this becomes the decreasing order.
91
00:14:13,670 --> 00:14:16,220
So, you observe that this gives a
92
00:14:16,220 --> 00:14:23,220
Bitonic sequence of size 8. How you will be
arranging? That part we will discuss later.
93
00:14:51,110 --> 00:14:52,370
Second phase.
Now, third phase is, you have arranged the
94
00:14:52,370 --> 00:14:57,820
data. You have Bitonic sequence here and another
Bitonic sequence here, right. So,
95
00:14:57,820 --> 00:15:04,759
you arrange the data in such a way that you
get 2 Bitonic sequences, each of size 8. Basically,
96
00:15:04,759 --> 00:15:11,029
you will be getting this one and
97
00:15:11,029 --> 00:15:18,029
then, this one. So, you get Bitonic sequence
of size 61, right. This is increasing order
98
00:15:18,889 --> 00:15:22,209
and this would be in decreasing order. So,
if
99
00:15:22,209 --> 00:15:29,209
I see from this point of view, then it will
become a Bitonic sequence in the third phase.
100
00:15:31,480 --> 00:15:36,690
So, in the fourth phase, you have a Bitonic
101
00:15:36,690 --> 00:15:43,690
sequence. So, you can easily get a sorted
sequence. So, basically at the end of the
102
00:15:52,889 --> 00:15:58,370
fourth phase, you get the sorted sequence.
At the end of the third phase, you get sorted
103
00:15:58,370 --> 00:16:05,370
sequence. So, the strategy is such that, it
should be such that, at the end of every
104
00:16:06,970 --> 00:16:13,970
phase, you get some number of Bitonic sequences.
This is first one and the second one, it should
105
00:16:16,329 --> 00:16:18,860
collapse in such a way that, after
106
00:16:18,860 --> 00:16:25,860
logging time, you will be able to get the
sorted sequence, right. So, what you observe?
107
00:16:27,269 --> 00:16:33,610
First thing is that, you do the merging with
108
00:16:33,610 --> 00:16:40,610
respect to the row, right. That is horizontal
you merge it. Then, you get Bitonic sequence
109
00:16:47,750 --> 00:16:52,190
consisting of two halves, which you
110
00:16:52,190 --> 00:16:59,190
need to merge vertically. Here, you get this
one and this sub block and you need to merge
111
00:17:04,000 --> 00:17:07,310
them horizontally, right. Now here,
112
00:17:07,310 --> 00:17:12,380
again you have one sorted sequence and another
sorted sequence, this forms a Bitonic sequence
113
00:17:12,380 --> 00:17:13,530
and you have to merge it
114
00:17:13,530 --> 00:17:16,569
vertically and so on.
115
00:17:16,569 --> 00:17:23,300
So, once you do the horizontal one and next
you should do the vertical one. Horizontal,
116
00:17:23,300 --> 00:17:24,980
vertical like that to get the, ultimately
117
00:17:24,980 --> 00:17:29,820
find out after the logging session, you get
the sorted sequence. Is it ok? The strategy
118
00:17:29,820 --> 00:17:34,480
is clear? So, first let us discuss about,
so
119
00:17:34,480 --> 00:17:41,270
basically we need to know one is horizontal
merge and another one is vertical merge, right.
120
00:17:41,270 --> 00:17:45,140
If I know this one, then we do
121
00:17:45,140 --> 00:17:52,140
iteratively. One after the other one to get
this merge.
122
00:17:53,270 --> 00:18:00,270
Now, vertical merge of Bitonic sequence consists
of two algorithms. One is known as row merge
123
00:18:20,840 --> 00:18:27,840
and another one is column
124
00:18:30,720 --> 00:18:32,690
merge.
125
00:18:32,690 --> 00:18:39,690
So, first let us discuss about the row merge.
126
00:18:44,910 --> 00:18:51,910
Let us assume that there are k processors,
P 0, P 1, P 2, P k minus 1 in a form of row.
127
00:19:42,840 --> 00:19:49,840
P i contain a i, a 0, a 1, a k minus 1is a
128
00:19:53,780 --> 00:20:00,780
Bitonic sequence. So, what do you have basically
is, you have the processors like that and
129
00:20:42,120 --> 00:20:49,120
the data is
130
00:20:53,510 --> 00:20:56,650
like this. So, what I am
131
00:20:56,650 --> 00:21:03,650
going to do in the Bitonic sequence case is,
p i should be computed with p i plus k by
132
00:21:05,100 --> 00:21:06,430
2. Agreed?
133
00:21:06,430 --> 00:21:13,430
So, basically these data has to be moved here.
These data has to be moved here. These data
134
00:21:13,500 --> 00:21:20,500
has to be moved here and then
135
00:21:21,890 --> 00:21:28,890
compare, right. There will be one accepted
element and another is rejected element. The
136
00:21:34,730 --> 00:21:38,370
rejected element you send back this side
137
00:21:38,370 --> 00:21:45,370
again, right. So, what you will get? This
is the Bitonic sequence and this becomes another
138
00:21:48,940 --> 00:21:52,380
Bitonic sequence. Agreed? Iteratively,
139
00:21:52,380 --> 00:21:59,380
again you call row merge to this one and row
merge to this one and so on. You will be getting
140
00:21:59,430 --> 00:22:02,100
ultimately the sorted sequence.
141
00:22:02,100 --> 00:22:09,100
So, if it is the case, so I can write row
merge k and we assume data is initially stored
142
00:22:19,700 --> 00:22:22,190
in R r register.
143
00:22:22,190 --> 00:22:29,190
Assume data is stored initially in R r register.
R r contains a i. Assume data contains with
144
00:22:35,080 --> 00:22:42,080
R r register. So, once you want to bring
145
00:22:42,470 --> 00:22:49,470
this data from here to here, this data has
to be saved first. Agreed or not? Because,
146
00:22:51,280 --> 00:22:54,620
this data is also in R r register and routing
has
147
00:22:54,620 --> 00:23:01,620
to be done through R r only. So, you move
this data first to R s area.
148
00:23:01,690 --> 00:23:08,690
So, each processor p i, i is 0 1 to k by 2
minus 1 moves a i from R r to R s and then,
149
00:23:36,350 --> 00:23:43,350
next one is, each processor p i, i is equal
k by
150
00:23:50,670 --> 00:23:57,670
2 k minus 1 sends its data, once I write that
it sends its data, it must be in R r register
151
00:24:04,970 --> 00:24:11,970
to p i minus k by 2. Next is, each processors
152
00:24:17,690 --> 00:24:24,690
p i i is 0 1 k by 2 minus 1. What it does?
It compares, right and performs compare exchange
153
00:24:46,080 --> 00:24:53,080
operations between
R r and R s.
154
00:24:58,290 --> 00:25:05,230
Now, once I perform the R r compare exchange
operation between R r and R s, the accepted
155
00:25:05,230 --> 00:25:08,080
element is in R s and rejected
156
00:25:08,080 --> 00:25:15,080
element is in R r. That is true always. Accepted
element will be in R s area and rejected element
157
00:25:15,400 --> 00:25:21,890
will be in R r area. Now, if it is
158
00:25:21,890 --> 00:25:28,890
the case, now this rejected element has to
be sent back to the other part of the area.
159
00:25:29,380 --> 00:25:36,380
So, what I do is, this process p i i is 0
1 k by 2
160
00:25:46,850 --> 00:25:53,850
minus 1 sends this beta to p i plus 1 k by
2, right. So, the rejected element has come
161
00:26:04,430 --> 00:26:09,420
here and that is in R r area.
162
00:26:09,420 --> 00:26:16,420
Now, R s contains first k by 2 processors,
means it contains all the accepted elements.
163
00:26:24,890 --> 00:26:31,390
So, each process, so that you can start
164
00:26:31,390 --> 00:26:38,390
again, p i i is 0 1 k by 2 minus 1 performs
exchange operation between R r and R s. Now,
165
00:27:02,870 --> 00:27:09,370
all the details are in R r registers. So,
we
166
00:27:09,370 --> 00:27:16,370
can call row merge k by 2 on p 0 p k by 2
minus 1 and R M k by 2 on p k by 2 to p k
167
00:27:40,090 --> 00:27:47,090
minus 1 simultaneously. Any please tell me.
168
00:27:52,330 --> 00:27:59,330
This one. Otherwise, see here, compare and
exchange is doing, now R s contains all accepted
169
00:28:04,880 --> 00:28:07,420
elements and R r is all the rejected
170
00:28:07,420 --> 00:28:10,970
elements. Now, this rejected element has to
come here .
171
00:28:10,970 --> 00:28:17,970
Now, once you have sent the rejected elements
here, now this R r contains all junk things
172
00:28:18,070 --> 00:28:22,160
and I have to get back this R s thing
173
00:28:22,160 --> 00:28:27,950
here, so that, recursive I can do. Because,
in the initial thing, where I decided that,
174
00:28:27,950 --> 00:28:32,710
all the data is are in R r register, right.
175
00:28:32,710 --> 00:28:39,710
Initially, think that data are in R r. So,
if data is in R r, so to call this one, I
176
00:28:43,670 --> 00:28:47,590
must have the data in R r registers. So, to
do that, just I
177
00:28:47,590 --> 00:28:51,640
am performing this operation, right.
178
00:28:51,640 --> 00:28:58,640
Now, in order to compute the time complexity
for this t r
row merge k, compare row merge k exchange
179
00:29:30,110 --> 00:29:35,510
row merge k.
180
00:29:35,510 --> 00:29:42,510
Now, the thing is that, we have to go there.
I have mentioned about boundary the conditions.
181
00:29:43,310 --> 00:29:44,580
Because, once it is recursive, I
182
00:29:44,580 --> 00:29:51,580
could tell about the boundary solutions, right.
So, what should be the boundary condition?
183
00:29:57,460 --> 00:30:04,460
Whenever k is more than 1, you do it. So,
if k is greater than 1, agreed, you do this.
184
00:30:16,280 --> 00:30:23,280
If it is the same, So, if k is 1, How many
185
00:30:45,370 --> 00:30:52,370
routings you need? 0. Otherwise? How did you
do get that? You are also supporting that.
186
00:31:27,460 --> 00:31:34,460
You have, now you have to move this data from
here to here. How much time you need? How
187
00:31:34,690 --> 00:31:37,380
many routings you need? k by 2
188
00:31:37,380 --> 00:31:42,490
routings you need. Again, you have to pump
the data. So, another k by 2.
189
00:31:42,490 --> 00:31:49,490
So, you have k plus time you need, on row
k by two . Agreed?
190
00:31:58,060 --> 00:32:05,060
Now, so routing part is over. So, what
is the routing? This one and this one. Now,
can you tell me compare exchange? How many
191
00:32:41,770 --> 00:32:48,770
compare exchange? This is all can be simultaneously,
plus t compare to, agreed? So, compare exchange
192
00:33:04,340 --> 00:33:08,770
is also over.
193
00:33:08,770 --> 00:33:15,770
Then, exchange operations? It is parallel.
Why I am sending the data from here to here?
194
00:33:21,430 --> 00:33:24,420
This comes from here to here. This
195
00:33:24,420 --> 00:33:30,960
comes here to here, but, how you are going
to bring this element here? This will come
196
00:33:30,960 --> 00:33:33,660
here, here, here, here. While this element
is
197
00:33:33,660 --> 00:33:40,660
here, this element is here, right. So, it
is, see, this is the pipeline technique, right.
198
00:33:44,490 --> 00:33:49,520
So, you need by distance to cover. For him,
this
199
00:33:49,520 --> 00:33:56,440
distance to be covered. For him, this distance
to be covered, which is k by 2. Agree?
200
00:33:56,440 --> 00:34:03,440
Now, 0, if t equals to 1 and 2 plus t e R
M k by 2, then two on the . Now, first let
201
00:34:57,580 --> 00:35:00,330
us find out the solution of this one? What
is the
202
00:35:00,330 --> 00:35:04,040
solution of this?
203
00:35:04,040 --> 00:35:11,040
Suppose k equals two the power 1 Are you sure
i or i minus 1? I do not know. i or i minus
204
00:35:22,720 --> 00:35:27,960
1? i? 100 percent right. I do not know.
205
00:35:27,960 --> 00:35:34,960
i? Fine. Then, it is log k. That is it.
206
00:35:41,820 --> 00:35:44,220
Then, you will be writing this is 2 log k.
You please check whether it is i or i minus
207
00:35:44,220 --> 00:35:47,980
1. Otherwise, it is log k. Agreed? So, because
208
00:35:47,980 --> 00:35:54,980
this is 2 times, constant times, so it is
masters theorem. What about this part? k log
209
00:35:56,730 --> 00:36:03,730
k? How? Usually, k log k, then what for I
am
210
00:36:05,830 --> 00:36:12,830
doing all these things? Because n log n is
starting time and sequential merging time
211
00:36:16,030 --> 00:36:21,670
this n log n.
212
00:36:21,670 --> 00:36:28,670
Let us see T r k R M is equals to k plus T
r R M k by 2, which is k plus k by 2 plus
213
00:36:43,940 --> 00:36:50,940
T r R M k by 4 k plus k by 2 plus k by 4.
214
00:37:01,830 --> 00:37:08,830
When k, this is k, then I get 1 and k means
2 to the power i. So, when this is one, what
215
00:37:29,530 --> 00:37:36,530
I will write here? k by 2 to power n. No.
216
00:37:38,120 --> 00:37:43,700
Are you sure? When I am writing 4 here, I
am writing 2 to the power 1. When I am writing
217
00:37:43,700 --> 00:37:46,920
2 to the power i, it will 2 to the power
218
00:37:46,920 --> 00:37:53,920
i minus 1, right and this is 0. So, you get
1 plus half plus 4; 2 times k minus 2.
219
00:38:22,050 --> 00:38:29,050
So, this solution is; is that ok? So, this
is the number of routings you need. Now, if
220
00:38:52,280 --> 00:38:56,750
I tell that can you prove it that it gives
the
221
00:38:56,750 --> 00:39:03,750
sorted sequence from a Bitonic sequence, right.
Your input is in this row mode. Input, I told
222
00:39:07,110 --> 00:39:09,310
that the row contains a Bitonic
223
00:39:09,310 --> 00:39:16,310
sequence and after row merge call, I get a
sorted sequence. Now, obviously this algorithm
224
00:39:19,280 --> 00:39:21,660
you have to prove that it gives you a
225
00:39:21,660 --> 00:39:22,830
sorted sequence.
226
00:39:22,830 --> 00:39:29,830
Any idea? Does it not obvious? Because, a
i is compared to a i plus n and then, I am
227
00:39:43,780 --> 00:39:47,340
making it two rows, this row and this row
228
00:39:47,340 --> 00:39:54,340
and then, again we recursively calling. I
am not changing any or I am not making any
229
00:39:54,520 --> 00:39:58,070
new strategy or new things I am introducing
230
00:39:58,070 --> 00:40:05,070
into that, right. Now, if it is case, so row
merge gives you the sorted sequence and the
231
00:40:06,200 --> 00:40:09,390
second thing is that column merge. In the
232
00:40:09,390 --> 00:40:16,390
column merge, let us put the name C M and
j is the number of elements in that column.
233
00:40:19,340 --> 00:40:26,340
Same way, I can do it. Instead of assuming
that it is in the form of row and I am assuming
234
00:40:27,270 --> 00:40:29,870
that it is in the form of column, right.
235
00:40:29,870 --> 00:40:36,870
So, column merge will also give you the sorted
sequence form if the elements form a Bitonic
236
00:40:39,600 --> 00:40:41,600
sequence in that column. Agreed?
237
00:40:41,600 --> 00:40:48,600
So, the time complexity for this, I can write
t r c m j is equals to 2 j minus 2 t c c m
238
00:40:58,600 --> 00:41:05,600
j, it is log j and t e c m j is your 2 times
log j.
239
00:41:17,050 --> 00:41:24,050
Now, if you know the row merge and column
merge, you really know what it does.
240
00:41:28,850 --> 00:41:35,850
Suppose you have j cross j columns and j row
and j columns, right. Suppose you have this
241
00:41:56,140 --> 00:41:58,120
and this forms a Bitonic sequence and
242
00:41:58,120 --> 00:42:05,120
this is in increasing order and this is in
decreasing order and combining this, it forms
243
00:42:05,270 --> 00:42:11,930
a Bitonic sequence, right. Let us assume that
244
00:42:11,930 --> 00:42:18,930
this j by 2. So, first you, what you have
to do? This element is compared with this
245
00:42:22,580 --> 00:42:28,590
element. a i is compared with a i plus n.
So this,
246
00:42:28,590 --> 00:42:35,590
position of this is a of j by 2 minus 1 into
k. This is the, well, elements position of
247
00:42:45,970 --> 00:42:49,770
this one and this elements position, if I
expand it
248
00:42:49,770 --> 00:42:56,770
in 1 row, at a sequence, this position is
a j by 2 minus 1 k plus 1, right and this
249
00:43:02,320 --> 00:43:07,930
is your a 1. So, this a 1 has to be compared
with
250
00:43:07,930 --> 00:43:13,320
this elements. I did not or not?
Similarly, this element has to be compared
251
00:43:13,320 --> 00:43:20,320
with this element. Now, think about this element
and this element has to be compared
252
00:43:23,140 --> 00:43:30,140
with this element. This element has to be
compared with this element and so on. So,
253
00:43:34,190 --> 00:43:38,240
basically I can think that these are several
254
00:43:38,240 --> 00:43:45,240
columns you have. If I do the column merge,
what will I get? If I do the column merge,
255
00:43:46,910 --> 00:43:53,910
I
get a Bitonic sequence in this job and
256
00:43:59,210 --> 00:44:06,210
another Bitonic sequence in this job. Yes
or no? So, but the size is j by 2. Again,
257
00:44:14,740 --> 00:44:17,650
you do this column merge again here. Columns
258
00:44:17,650 --> 00:44:24,650
merge here again and then, you get like this
size. Again you do the columns merge and you
259
00:44:25,350 --> 00:44:30,390
get this size. Finally, you will get
260
00:44:30,390 --> 00:44:37,390
Bitonic sequence in each row. Agreed? This
finds the property that these elements are
261
00:44:38,890 --> 00:44:40,170
smaller than these elements. These
262
00:44:40,170 --> 00:44:45,830
elements are smaller because that is the property
of Bitonic. Now, you do the row merge. You
263
00:44:45,830 --> 00:44:47,880
do the row merge and then, you
264
00:44:47,880 --> 00:44:54,880
combine these things and you get the sorted
sequence. Finally, you will get the sorted
265
00:45:04,280 --> 00:45:04,970
sequence.
266
00:45:04,970 --> 00:45:11,970
Tell me again? First row elements are smaller
than the second row. But, within the row,
267
00:45:12,300 --> 00:45:16,440
that forms a Bitonic sequence. That is the,
268
00:45:16,440 --> 00:45:23,440
that is not sorted. The content of these elements
is Bitonic sequence and these elements are
269
00:45:24,040 --> 00:45:25,860
smaller than these elements. These
270
00:45:25,860 --> 00:45:32,320
elements are smaller than these elements and
so on. Now, you have to do the row merge here,
271
00:45:32,320 --> 00:45:38,550
right. So, vertical merge, if I write j
272
00:45:38,550 --> 00:45:45,550
comma k, first what you do? You do the column
merge and then, you do the row merge. So,
273
00:45:46,960 --> 00:45:52,730
you do first column merge, then you
274
00:45:52,730 --> 00:45:59,730
do the row merge. This is your vertical merge
algorithm. We will consider one example to
275
00:46:01,090 --> 00:46:04,490
see how it works. Now, the time
276
00:46:04,490 --> 00:46:11,490
complexity for that is t v m r routing j comma
k is your 2 times j plus k minus 4, compare
277
00:46:25,380 --> 00:46:32,380
vertical merge j comma k is log j k,
278
00:46:39,890 --> 00:46:46,890
exchange vertical merge j comma k is 2 times
log j k. Just I am combining these two algorithms.
279
00:46:54,400 --> 00:47:01,400
One example, you have, suppose 4 cross 8.
But you have to give me 32 elements. Let us
280
00:47:30,060 --> 00:47:37,060
do here, 1 2 3 4 5 6 7 8 9 10 11 12 13 14
281
00:47:44,900 --> 00:47:51,900
15 16 17 18 19 20 21 22 23 24 25 26 27 28
29 30 31 32. So, you have, suppose this is
282
00:48:21,140 --> 00:48:24,580
the Bitonic sequence you have, right. This
283
00:48:24,580 --> 00:48:31,580
is in the increasing order and this is decreasing
order. Now, if I do the column merge, assuming
284
00:48:33,200 --> 00:48:35,640
this is one column, this is another
285
00:48:35,640 --> 00:48:41,810
column, another column, so what I will get?
What I will get? Tell me. If I do the column
286
00:48:41,810 --> 00:48:48,810
merge here? I will be getting 1 7 10 15 19
287
00:49:24,210 --> 00:49:31,210
24 27 31. What about this one? 2 5 11 14 20
23 28 30 and then, you get 4 6 12 13 17 21
288
00:50:12,840 --> 00:50:19,840
26 and 29, 3 8 9 16 18 22 25 32. So,
289
00:50:27,250 --> 00:50:34,250
column merge you will be getting that and
you observe that every element has got its
290
00:50:38,000 --> 00:50:39,540
own row.
291
00:50:39,540 --> 00:50:46,540
But within the row, it forms a Bitonic sequence,
right. If you do the row merge, you will be
292
00:50:48,480 --> 00:50:51,740
getting, this is column merge. But
293
00:50:51,740 --> 00:50:58,740
while trying at home, you use all the steps
of column merge. Within the column merge,
294
00:51:00,280 --> 00:51:01,700
you will be getting the column merge j by
295
00:51:01,700 --> 00:51:08,700
3, then column merge j by 4 and so on. So
you will be getting here row merge, 1 2 3
296
00:51:20,380 --> 00:51:27,380
4 5 6 7 8, right. Because, you know, from
297
00:51:38,000 --> 00:51:45,000
here to here, it involves, first this type
of thing, row merge 4 and then, row merge
298
00:51:48,470 --> 00:51:55,470
2. Row merge 2 will be this one. Yes or no?
Say,
299
00:51:57,520 --> 00:52:04,520
for this case, 1 2 4 3, so what you will be
getting? Row merge these two. go back, so
300
00:52:04,990 --> 00:52:07,680
you will be getting 1 2 4 3. Then row merge
301
00:52:07,680 --> 00:52:10,390
size, so then only you will be getting 1 2
3 4, right.
302
00:52:10,390 --> 00:52:17,390
For this case, you will be getting 10 11 12
9. First you do merging these. So, you will
303
00:52:31,100 --> 00:52:36,180
be getting, 12 is coming here and 9 will be
304
00:52:36,180 --> 00:52:43,180
coming here and accepted elements will be
retained and rejected will be sent back. So,
305
00:52:46,830 --> 00:52:53,830
10 will be here; 12 will be here; 11 will
be
306
00:53:04,100 --> 00:53:11,100
there and then, row merge compares to 9 10
11 12. So, this is R M 4 and this R M 2. Which
307
00:53:20,150 --> 00:53:21,140
one? This one or this one?
308
00:53:21,140 --> 00:53:27,600
First one indicates yes and second one indicates
no. See here, is tilted by this direction
309
00:53:27,600 --> 00:53:30,460
or this direction, that is here. Depending
310
00:53:30,460 --> 00:53:39,300
up on the south Indian or north Indian, all
those things, but in both the case, if you
311
00:53:39,470 --> 00:53:43,400
get this and this; that is always known.