1
00:00:17,830 --> 00:00:22,110
So, in the last class, we were discussing
about what we discuss, we discuss about the
2
00:00:22,110 --> 00:00:25,630
horizontal merge. Now, of vertical merge
3
00:00:25,630 --> 00:00:31,150
vertical merge, now today first we will be
discussing horizontal merge and then we will
4
00:00:31,150 --> 00:00:33,260
discuss the main sorting algorithm. Finally,
5
00:00:33,260 --> 00:00:40,260
we will try to consider an example of which
because the through which we can say how the
6
00:00:42,750 --> 00:00:45,530
algorithm wants.
7
00:00:45,530 --> 00:00:52,530
The horizontal merge first part, the problem
is that suppose you have J cos k
the problem is this is increasing order, this
8
00:01:17,070 --> 00:01:17,290
is
9
00:01:17,290 --> 00:01:24,290
decreasing order and you want to merge it.
In order to do that, first we need to define
10
00:01:38,920 --> 00:01:43,310
say two column merge that problem is that
11
00:01:43,310 --> 00:01:50,310
you have one column J rows
and 2 J elements.
12
00:01:58,760 --> 00:02:05,760
You have a 0, a 1, a 2, a 2 simplicity down
there is 3 1, a 2, a 2, J this two J elements
13
00:02:18,840 --> 00:02:25,840
you have which is a bitonic sequence in the
14
00:02:35,980 --> 00:02:38,700
second line absent one is with us.
15
00:02:38,700 --> 00:02:45,700
The other one is 18, 17, 4 plus 4, 8, 9, 7,
17, so a 1, a 2, a 2 J is a bitonic sequence
16
00:02:58,780 --> 00:03:03,099
and the elements are stored in a column of
J
17
00:03:03,099 --> 00:03:10,099
rows in such a way that you have a 1, a 2,
a J and then a J plus 1 to a to w J.
18
00:03:25,010 --> 00:03:32,010
Let us assume that this delta is stored like
this P 0, P 1, P J minus 1, this P 0, P 1,
19
00:03:41,060 --> 00:03:48,060
P J minus 1 are the processors and this is
in R s
20
00:03:48,980 --> 00:03:55,980
resister this is in R k resister or R r resister.
So, you have a 1, a 2 a 2 J elements in form
21
00:04:02,410 --> 00:04:05,599
a bitonic sequence and we have a column
22
00:04:05,599 --> 00:04:12,599
of J rows r, n J rows. Each row is assign
to a processors p 0 to p J minus 1 and i th
23
00:04:14,959 --> 00:04:21,959
row contains the a i and a i plus J, a i is
in R s
24
00:04:26,410 --> 00:04:33,410
resister and a i plus J is in R r resister.
So, what you are going to do it see the simple
25
00:04:38,479 --> 00:04:40,490
thing is there in the bitonic sequence is
based
26
00:04:40,490 --> 00:04:44,979
on the only one property that a i is compared
with a i plus 8.
27
00:04:44,979 --> 00:04:51,979
So, this is ready for you that this has to
be compared this has to be compared, so if
28
00:05:00,050 --> 00:05:02,969
you compare and rejected element will be in
29
00:05:02,969 --> 00:05:09,969
this side and accepted element will be this
side. Now, after that I want to do it recursively,
30
00:05:13,879 --> 00:05:20,279
so what happens here after comparing
31
00:05:20,279 --> 00:05:25,119
these elements will be these elements will
be a bitonic sequence. These elements will
32
00:05:25,119 --> 00:05:27,479
form a bitonic sequence and all these
33
00:05:27,479 --> 00:05:32,349
elements will be less than or equals to this
one.
34
00:05:32,349 --> 00:05:39,349
Then, recursively will be solving these two,
so same idea that you have this one compared
35
00:05:39,969 --> 00:05:43,490
a change compared a change. Now,
36
00:05:43,490 --> 00:05:50,490
you have to bring these elements in this zone
and these elements should go in this zone.
37
00:05:59,169 --> 00:06:01,949
If I then this will be comes a bitonic
38
00:06:01,949 --> 00:06:06,150
sequence, this will be another bitonic sequence
and all these elements should be smaller than
39
00:06:06,150 --> 00:06:13,150
these elements, what I am doing this
40
00:06:17,210 --> 00:06:22,240
is compared with this the rejected elements
are lying here accepted elements are lying
41
00:06:22,240 --> 00:06:29,159
here. Now, I want to make it these two
42
00:06:29,159 --> 00:06:34,759
halves, you know to make these two halves
and recursively I want to use it. So, these
43
00:06:34,759 --> 00:06:38,379
halves should be in touch with this half so
44
00:06:38,379 --> 00:06:41,139
that this forms a bitonic sequence this form.
45
00:06:41,139 --> 00:06:48,139
Another bitonic sequence and all these elements
should be smaller than these elements and
46
00:06:48,569 --> 00:06:55,569
then you do it recursively say for
47
00:07:01,360 --> 00:07:08,360
example, tell me bitonic sequence of 16 elements
1, 2, 3, 4, 5 for a 1 2. So, this is a bitonic
48
00:07:48,949 --> 00:07:54,960
sequence you have and this is a R s
49
00:07:54,960 --> 00:08:01,960
resister and this is a R r resister, what
we are doing that a i is to be compared with
50
00:08:05,189 --> 00:08:09,139
a i plus n and the accepted elements in R
s area
51
00:08:09,139 --> 00:08:16,139
and rejected elements in R r resister.
So, if it is the case you get the result of
52
00:08:30,800 --> 00:08:37,800
this like, now you observe you observe this
becomes a bitonic sequence and this becomes
53
00:08:52,220 --> 00:08:59,220
another bitonic sequence and is a by the definition
of the by the carom of bitonic sequence. Now,
54
00:08:59,640 --> 00:09:01,310
you want to use the same
55
00:09:01,310 --> 00:09:08,310
algorithm you want to same algorithm for what
you have. So, what I want that these elements
56
00:09:09,850 --> 00:09:13,210
should be here so that I get the
57
00:09:13,210 --> 00:09:20,210
bitonic sequence and these elements should
be here so that I get another bitonic sequence.
58
00:09:22,140 --> 00:09:29,140
So, what I will do it, I want to inter change
this thing, so if I inter change it, I get
59
00:09:50,520 --> 00:09:57,520
1, 2, 5, 8, 7, 6, 4, 3, you get 15, 14, 12,
11, 9, 10,
60
00:10:07,010 --> 00:10:14,010
13, 16. So, you observe that you get two bitonic
sequence and all these elements will be smaller
61
00:10:14,500 --> 00:10:17,920
than these elements. Now, again
62
00:10:17,920 --> 00:10:24,920
you perform two halves compare a change and
then inter change these two elements, so you
63
00:10:35,280 --> 00:10:42,280
get here 1, 1, 7, 2, 6, 4, 5, 3, 8, 9, 15,
64
00:10:56,240 --> 00:11:03,240
10, 14, 12, 11, 13, 16. If I inter change
these two, I get 1, 2, 4, 3, 7, 6, 5, 8, 9,
65
00:11:36,740 --> 00:11:43,740
10, 12, 11, 15, 14, 13, 16.b. Now, you observe
that
66
00:11:49,380 --> 00:11:54,500
this is a cluster of four element, this is
a cluster another four elements and each cluster
67
00:11:54,500 --> 00:11:57,940
is a bitonic sequence and again you do
68
00:11:57,940 --> 00:12:04,940
compare a change.
69
00:12:07,090 --> 00:12:14,090
So, compare a change and then inter change,
so you will get
the and 5, 6, 7, 8, 9, 10, 12, 11, 13, 14,
70
00:12:41,990 --> 00:12:45,720
15, 16 and then you get
71
00:12:45,720 --> 00:12:52,720
basically eight such bitonic sequence you
just do the compare a change you get 1, 2,
72
00:13:05,280 --> 00:13:12,280
3, 4, 5, 6, 7, 8. So, you get the sorted
73
00:13:21,070 --> 00:13:28,070
sequence in this form right here. Now, if
you observed that I could have done after
74
00:13:40,930 --> 00:13:43,750
doing the compare exchange, we observe that
75
00:13:43,750 --> 00:13:48,700
this sequence is the bitonic sequence this
sequence is the bitonic sequence and all these
76
00:13:48,700 --> 00:13:49,460
elements should be smaller than these
77
00:13:49,460 --> 00:13:51,390
elements.
Now, I could have done the column merge, I
78
00:13:51,390 --> 00:13:58,390
could have done the column merge and I could
have could have got this sorted this
79
00:14:01,180 --> 00:14:08,180
is also sorted sequence. It is based on the
bitonic sequence, but is the problem is that
80
00:14:13,560 --> 00:14:18,050
I do not achieve the goal like that 1, 2,
3, 4,
81
00:14:18,050 --> 00:14:24,410
5, 6, 7, 8 like that which I need for horizontal
merge because is the horizontal merge it should
82
00:14:24,410 --> 00:14:26,350
be like this not this way.
83
00:14:26,350 --> 00:14:28,590
So, that is the reason why instead of doing
the column merge we are doing that interchange
84
00:14:28,590 --> 00:14:33,020
first and then we are a repeating that
85
00:14:33,020 --> 00:14:40,020
two column merge so that data is to final
data is told in this form A 2 column merge.
86
00:15:02,920 --> 00:15:09,920
First step is that perform compare exchange
87
00:15:18,060 --> 00:15:25,060
operation
88
00:15:35,690 --> 00:15:42,690
between R s and R r registers, we have already
assume the data is in the form that a 1, a
89
00:15:48,110 --> 00:15:50,420
2, a 3 a 2 J in such way that a i
90
00:15:50,420 --> 00:15:57,420
and a i plus J is in the i th row and R r
R s and R r registers respectively.
91
00:16:01,150 --> 00:16:08,150
Now, if J is greater than 1, if J is equals
to 1 that means there is only one row and
92
00:16:10,700 --> 00:16:13,339
that means that you have the only two elements
93
00:16:13,339 --> 00:16:18,410
which form the bitonic sequence, just one
compare exchange is sufficient to make it
94
00:16:18,410 --> 00:16:25,410
sorted form, now if J is greater than 1.
95
00:16:27,150 --> 00:16:32,190
What I am going to do that rejected element
has to be compare has to be inter change with
96
00:16:32,190 --> 00:16:39,190
accepted element of that say inter
97
00:16:42,279 --> 00:16:49,279
change content of R r of P i, i is zero to
J by 2 minus 1 with R s of P k, k is J by
98
00:17:17,980 --> 00:17:24,980
2 to J minus 1. Now, how we will going to
do this
99
00:17:27,799 --> 00:17:34,799
see what we told
this has to be inter change how are we going
to do that x equals to inter change, what
100
00:17:54,009 --> 00:17:54,369
is x.
101
00:17:54,369 --> 00:18:01,369
How are you going to get these two values,
this is in P i and this is an say P k and
102
00:18:11,840 --> 00:18:18,590
it is in the form of mesh P i connected to
four
103
00:18:18,590 --> 00:18:24,139
neighbor only.
Student: Sir, more contents of a R r are there
104
00:18:24,139 --> 00:18:29,330
in R t.
Yes, that is the reason why we need R t, so
105
00:18:29,330 --> 00:18:36,330
the element here you moved to R t, then bring
down next step you bring down all
106
00:18:40,139 --> 00:18:47,139
these elements here then you inter change
this then you bring that, so this is the step
107
00:18:53,179 --> 00:18:57,960
and then finally, you move again these
108
00:18:57,960 --> 00:18:58,820
elements.
109
00:18:58,820 --> 00:19:05,820
Now, after inter changing you will be doing
two column merge J by 2 with J P 0 P J by
110
00:19:20,460 --> 00:19:27,460
2 minus 1 and two column merge J by 2 p J
111
00:19:32,759 --> 00:19:39,759
by 2 to p J minus 1. Simultaneously, both
of them can be done in paragraph, now if it
112
00:19:49,110 --> 00:19:55,649
is the case, then what is the time complexity
113
00:19:55,649 --> 00:20:02,649
what if notation are you what are complexity
t 1.
114
00:20:03,190 --> 00:20:10,190
I do not R 2 c and you have J, so routing
if J is equals to 1, then it is 0, there is
115
00:20:27,549 --> 00:20:34,549
no routing, now if J equals to more the if
J is
116
00:20:34,830 --> 00:20:41,830
greater than 1, you obviously have t R J by
2 2 c plus what is the routing required. This
117
00:21:01,739 --> 00:21:08,739
data has to be moved here and then again
118
00:21:09,220 --> 00:21:15,659
you will be moving back, so what is the routing
step total number.
119
00:21:15,659 --> 00:21:22,659
Student: Sir can we bring this data down and
take this data up.
120
00:21:22,799 --> 00:21:24,919
How?
Student: Say for this half.
121
00:21:24,919 --> 00:21:27,669
This this data you have bringing here.
And then next one take up.
122
00:21:27,669 --> 00:21:32,399
How are you going to because i told you the
routing and R r register is the only register
123
00:21:32,399 --> 00:21:38,799
through which.
We wants the above R r and R t. How R r will
124
00:21:38,799 --> 00:21:45,730
sent direct to R r only routing resister also.
Student: Sir, the initial value.
125
00:21:45,730 --> 00:21:50,249
This one you have to do here.
And R t.
126
00:21:50,249 --> 00:21:53,869
R t now you bring.
Similarly, in the left above.
127
00:21:53,869 --> 00:22:00,869
Student: Sir, the left part it is left.
This R r contents your original data R s contains
128
00:22:01,909 --> 00:22:08,909
you cannot touch R s r s this R s is all accepted
data this you want to retain here
129
00:22:10,690 --> 00:22:17,690
this contains all rejected data, but you want
to keep them here. Only this is the this part
130
00:22:18,429 --> 00:22:20,059
this part has to be inter change with this
131
00:22:20,059 --> 00:22:27,059
part in order to do that and your rotating
is done through R r resister only. So, you
132
00:22:28,369 --> 00:22:32,629
move this data here, you bring this data here,
133
00:22:32,629 --> 00:22:39,629
inter change these two, then you send back
the data here, then this you bring back what
134
00:22:44,710 --> 00:22:51,710
reverse way this you do one of method.
So, you need r routing R by 2, this side again
135
00:22:54,779 --> 00:23:01,779
R by 2 going back, you need R rotating R this
way r is J rotating. Now, what is the
136
00:23:02,159 --> 00:23:09,159
solution of this you assume J is to be equal
1, 5 up to 2, tell me what is the solution
137
00:23:29,899 --> 00:23:36,899
J plus J by 2 plus J by 4, 2 J or 2 J minus
2,
138
00:23:39,249 --> 00:23:46,249
what time we did it entering this 2 J minus
2. Next one is number of exchange operations
139
00:23:55,039 --> 00:23:58,100
and another one is number of
140
00:23:58,100 --> 00:24:03,230
transferring this and compare these things.
First, let us do the number of compare exchange
141
00:24:03,230 --> 00:24:10,230
it is one if J is equals to 1, otherwise it
is one plus P c 2 c J by 2 if J is greater
142
00:24:30,529 --> 00:24:37,529
than 1. There is no comparing exchange operation,
so I write 1 plus P c 2 c J by 2 and this
143
00:24:54,190 --> 00:24:58,159
solution is logged here this solution is
144
00:24:58,159 --> 00:25:03,470
logged here what about here there is no exchange
operations.
145
00:25:03,470 --> 00:25:10,470
So, J O if J equals to 1, this side I am writing
t e 2 c J by 2 plus if J greater than 1 how
146
00:25:21,190 --> 00:25:23,590
many exchange operations you have
147
00:25:23,590 --> 00:25:29,239
perform here, first is one is you are bringing
data here, then second is you have bringing
148
00:25:29,239 --> 00:25:35,970
Then, you are sending back through routine
then again you will be bringing the data here
149
00:25:35,970 --> 00:25:42,970
3. So, it is 3, so it is got answer is what
150
00:25:45,019 --> 00:25:52,019
said un this is one and this is 3, 3 log low
impact on 0 minus 1 are sure.
151
00:26:05,009 --> 00:26:12,009
So, if I put J equals 1, then it is become
2, tell me what 3 log J minus 1, suppose J.
152
00:26:19,970 --> 00:26:24,450
Let us assume the thing J equals to 2, answer
153
00:26:24,450 --> 00:26:31,450
should be J equals to 2, answer should be
3 J equals to 3 answer should J equals to
154
00:26:37,889 --> 00:26:44,889
4 answer should be not know, so what should
155
00:26:55,269 --> 00:27:02,269
be the log J.
156
00:27:12,859 --> 00:27:19,859
This is the thing on written, so it is 3 log
J if it is J equals to 1 it is 0.
157
00:27:51,759 --> 00:27:56,269
And 2 it is 3, 4 it is 6 and so on.
158
00:27:56,269 --> 00:28:02,809
It is there, so it is 3 log, so the two column
merge is done because you want data should
159
00:28:02,809 --> 00:28:09,059
be in such way that that all the elements
160
00:28:09,059 --> 00:28:16,059
in the first row smaller than the all the
elements in the second row and so on, so this
161
00:28:17,590 --> 00:28:23,899
idea is used in the horizontal merge.
162
00:28:23,899 --> 00:28:30,899
So, the elements you have in this forms all
there it forms a bitonic sequence and it bring
163
00:28:34,489 --> 00:28:41,489
this data here. So, initial if you remember
164
00:28:49,580 --> 00:28:56,580
this forms a bitonic sequence, now you will
observe that these elements, this is come
165
00:28:58,080 --> 00:29:05,080
here this also will form a bitonic sequence,
166
00:29:11,749 --> 00:29:18,749
you have two bitonic sequence.
Now, if this is an increasing order then this
167
00:29:24,659 --> 00:29:31,659
column is also in increasing order, if this
is decreasing order, and then this column
168
00:29:33,499 --> 00:29:33,759
is
169
00:29:33,759 --> 00:29:39,239
always decreasing order. Now, if I bring this
data here, this is forms a bitonic sequence
170
00:29:39,239 --> 00:29:42,820
because this was increasing order, this was
171
00:29:42,820 --> 00:29:49,820
decreasing order.
Similarly, if I bring this data here, I get
172
00:29:54,940 --> 00:30:01,940
another bitonic sequence here and so on, we
also and also if I merge the two column
173
00:30:06,100 --> 00:30:11,080
merge here, and then all the smaller elements
should be here next column element should
174
00:30:11,080 --> 00:30:18,080
be here and so on. Similarly, is the case,
175
00:30:23,470 --> 00:30:30,470
so what I do, I rejected element; I send back
again these rejected elements are rejected
176
00:30:31,139 --> 00:30:38,139
elements in the first row.
So, then these elements are smaller than these
177
00:30:39,710 --> 00:30:46,340
elements, so all these elements will be smaller
than these elements similar all these
178
00:30:46,340 --> 00:30:51,960
elements 0, 0, 2, 0 smaller than these elements.
So, even if I am sending the rejected elements,
179
00:30:51,960 --> 00:30:54,169
these elements are smaller than
180
00:30:54,169 --> 00:31:01,080
these elements and also each of these will
form a bitonic sequence. These will form a
181
00:31:01,080 --> 00:31:06,669
bitonic sequence and then you do the
182
00:31:06,669 --> 00:31:11,950
simple room merge each of them, we will find
the sorted sequence.
183
00:31:11,950 --> 00:31:18,950
So, let us consider first one example before
we discuss the algorithm 16 plus 16, 1, 2,
184
00:31:24,259 --> 00:31:31,259
4, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16,
17,
185
00:31:41,399 --> 00:31:48,399
18, 19, 30, 21, 32, 33, 34, 30, 5, 30, 6,
30, 7, 30, 8, 39, 30. So, you have suppose
186
00:32:06,009 --> 00:32:13,009
this thirty two elements and this form increasing
187
00:32:34,789 --> 00:32:41,789
order, this form decreasing order and you
observe this whole thing is a bitonic sequence.
188
00:32:44,599 --> 00:32:47,190
What we are doing, I am bringing these
189
00:32:47,190 --> 00:32:53,129
elements in the first column, these elements
in the second column, these elements in the
190
00:32:53,129 --> 00:32:55,759
third column, these elements in the
191
00:32:55,759 --> 00:33:02,759
fourth column. So, you get for I am not writing,
now this part
I get 1, 31, 2, 39, 4, 30, 6, 7, 35, 8, 33,
192
00:33:26,710 --> 00:33:33,710
13, 32, 15, 18, 16, 17, 19,
193
00:33:38,109 --> 00:33:45,109
14, 30, 12, 31, 11, 34, 10, 30, 7, 9, 38,
6, 35, 32, 3.
194
00:34:02,549 --> 00:34:09,549
Then, I do the two column merge for each column,
what I will get 1, 8, 9, 14, 19, 32, 34, 37,
195
00:34:31,470 --> 00:34:38,470
31, what about here, 2, 6, 12, 13, 30,
196
00:34:52,970 --> 00:34:59,970
28, 4, 5, 11, 13, 13, 11, 15, this 15, 11,
15, 18, then you get 3, 7, 10, 16, 17, 34,
197
00:35:38,670 --> 00:35:45,670
35, 22. Then, we send back the rejected elements
198
00:35:47,800 --> 00:35:54,800
to each counterpart, so I get 1, 2, 4, 3,
8, 6, 5, 7, 9, 12, 11, 10, 14, 13, 14, 13,
199
00:36:13,990 --> 00:36:20,990
15, 16, 19, 30, 21, 19, 30, 18, 17, 33, 32,
31, 34, 37,
200
00:36:33,280 --> 00:36:40,280
38, 36, 35, 31, 39, 30, 32, this
201
00:36:57,710 --> 00:37:03,770
is rejected element, I send back.
Now, first thing you observe here that all
202
00:37:03,770 --> 00:37:09,720
these elements are the smaller than these
elements, all these elements smaller than
203
00:37:09,720 --> 00:37:10,240
these
204
00:37:10,240 --> 00:37:16,880
elements, second thing you observed. Now,
after sending make each of them is bitonic
205
00:37:16,880 --> 00:37:20,580
sequence and all these elements such
206
00:37:20,580 --> 00:37:24,380
smaller than these elements, sorry all these
elements smaller than these elements all these
207
00:37:24,380 --> 00:37:25,900
elements smaller than these elements
208
00:37:25,900 --> 00:37:31,140
and so on. So, you can you introduce the room
merge here, room merge here, room merge here
209
00:37:31,140 --> 00:37:33,660
and so on and finally, you will get
210
00:37:33,660 --> 00:37:36,200
the sorted sequence.
211
00:37:36,200 --> 00:37:43,200
So, you have further to merge J comma k now
tell me what I will write initial data is
212
00:37:50,800 --> 00:37:55,640
a pertain this side whether it is an R s register
213
00:37:55,640 --> 00:38:01,020
or R r register data issues let us assume
data is in R r register in that case you assume
214
00:38:01,020 --> 00:38:05,270
a data is in R r register. Then, what you
215
00:38:05,270 --> 00:38:12,270
have to do what exchange first thing is that
compare how many compare, how can you shift
216
00:38:14,800 --> 00:38:21,800
it because they are all in a R r
217
00:38:23,180 --> 00:38:30,180
register that you have decided. So, perform
exchange operation in the first half, so first
218
00:38:33,720 --> 00:38:40,720
is perform exchange operation between R
219
00:38:51,310 --> 00:38:58,310
r and R s of P i or by p i i is what 1, 2,
1 or 0, 0 to k by 2 minus 1.
220
00:39:15,070 --> 00:39:22,070
So, actually P i J i if you write p i J, but
for all J for all J, so you have perform that
221
00:39:34,860 --> 00:39:41,860
then get the data of R r from p i k to p i
J for a
222
00:40:03,550 --> 00:40:10,550
not i J i is what, i refers to what i refers
to what row. So, I made mistake here this
223
00:40:15,140 --> 00:40:22,140
should be J this should be i, this should
be k by
224
00:40:35,950 --> 00:40:42,950
2 plus J and for all i J is 0 to k by 2 minus
1. Then, you perform two column merge for
225
00:41:03,660 --> 00:41:10,660
each column for each column right send
226
00:41:20,720 --> 00:41:27,720
data of R r from p i J to p i k by 2 plus
J for all i J is 0 to k by 2 minus 1. Next
227
00:41:59,480 --> 00:42:06,480
perform change operation
between R r and R s by P
228
00:42:18,650 --> 00:42:25,650
i J for all i J i k is 0 to k by 2 minus 1,
so I get back the accepted elements in R r
229
00:42:37,070 --> 00:42:38,380
of each.
230
00:42:38,380 --> 00:42:45,380
So, I have done up to this, now I have to
do the row merge here, you write assume there
231
00:42:59,080 --> 00:43:06,080
are 2 J bitonic sequences sequences each
232
00:43:09,610 --> 00:43:16,610
of size k by 2 sum are perform row merge k
by 2 on each bitonic sequence, so this is
233
00:43:45,310 --> 00:43:52,310
the steps involve P in further row merge.
234
00:43:53,280 --> 00:44:00,280
Now, a question is coming to obtain the time
complexity R t horizontal merge J comma k
235
00:44:11,190 --> 00:44:16,120
tell me what is the rotine. So, you have
236
00:44:16,120 --> 00:44:23,120
you have R 2 column merge J plus t r row merge
k by 2 plus this is whatever you needed that
237
00:44:45,220 --> 00:44:48,500
I have added whatever you needed
238
00:44:48,500 --> 00:44:55,500
here that I have added and what is the number.
So, this one routine step and this is another
239
00:45:05,210 --> 00:45:12,210
routine step, so this is k.
So, can you tell me what is the solution for
240
00:45:17,710 --> 00:45:24,710
this? What is the solution for this I have
now you obtain which is 2 J minus 2. What
241
00:45:25,060 --> 00:45:32,060
about this one row merge k by 2 row merge
k answer is what 2 k minus 2 k r it is k minus
242
00:45:45,890 --> 00:45:52,890
2 k shifted by k by 2 minus this
243
00:45:55,910 --> 00:46:02,910
constant actually plus k. So, this gives you
2 times J plus k minus 2, now what about exchange
244
00:46:14,590 --> 00:46:21,590
horizontal merge J comma k, what
245
00:46:22,340 --> 00:46:29,340
about time you need exchange horizontal merge
J.
246
00:46:29,960 --> 00:46:36,960
So, here one exchange operations here another
exchange operations, so two exchange operations
247
00:46:51,440 --> 00:46:58,440
we are doing, so what is t e this
248
00:46:58,590 --> 00:47:05,590
result is one k log J, what about this one,
what is the result? 2 log k by 2 plus J plus
249
00:47:20,790 --> 00:47:27,790
2. So, it is 3 log J plus 2 log k, now there
is no
250
00:47:35,900 --> 00:47:40,180
compare operations here except this here.
251
00:47:40,180 --> 00:47:47,180
So, I can write t c h m J k is what about
time, you need compare you need 2 C J plus
252
00:47:56,270 --> 00:48:03,270
T C r k by 2, this one belong to J k log J
253
00:48:09,100 --> 00:48:16,100
what about row merge log k by 2. So, I can
write log k minus 1, now you know what is
254
00:48:25,410 --> 00:48:27,310
what is vertical merge and what is
255
00:48:27,310 --> 00:48:33,630
horizontal merge you are ready to write the
sorting algorithm. So, when writing the sorting
256
00:48:33,630 --> 00:48:35,370
algorithm you have to keep it in mind
257
00:48:35,370 --> 00:48:36,800
is the bitonic it is a form of bitonic sequence,
one sequence should be keeping order another
258
00:48:36,800 --> 00:48:37,210
sequence has to be in decreasing
259
00:48:37,210 --> 00:48:37,340
order first.
260
00:48:37,340 --> 00:48:44,340
If you have the four plus 4, 4 plus 4, this
is a bitonic sequence this is another bitonic
261
00:48:45,150 --> 00:48:52,150
sequence you will be a, you will be a
262
00:48:54,770 --> 00:49:01,770
arranging the in this box. So, that a this
forms a bitonic sequence then you will be
263
00:49:12,370 --> 00:49:19,370
merging this one, so first it is horizontal
merge
264
00:49:20,380 --> 00:49:25,240
you have to do then vertical merge horizontal
merge vertical merge and so on. Every time,
265
00:49:25,240 --> 00:49:28,770
you have to keep track whether I have
266
00:49:28,770 --> 00:49:35,770
to keep it, there are increasing order or
decreasing order that has to be.
267
00:49:37,000 --> 00:49:44,000
So, I need to know what is the sage in number,
I need to know a sign function to tell if
268
00:49:51,120 --> 00:49:55,830
class one if it is in increasing order
269
00:49:55,830 --> 00:50:02,830
increasing order, how I will compute the sign
function, we will decide later one if it is
270
00:50:05,120 --> 00:50:10,570
decreasing order. So, I need to know the
271
00:50:10,570 --> 00:50:17,570
stage first stage second stage and so on and
a sign function and second thing I need to
272
00:50:27,130 --> 00:50:33,630
know a variable k to tell say your
273
00:50:33,630 --> 00:50:40,630
horizontal merge k plus k plus 2 k vertical
merge 2 k plus 2 k. What it means that first
274
00:50:46,770 --> 00:50:48,930
time you will be arranging this way
275
00:50:48,930 --> 00:50:54,940
consisting of two elements, in the second
stage you will get another one that instead
276
00:50:54,940 --> 00:50:59,380
of horizontal merge in vertical merge
277
00:50:59,380 --> 00:51:06,380
afterwards to size becomes 2 plus 2 k.
In second phase, you will get this side to
278
00:51:10,780 --> 00:51:17,780
knows, but four columns and then four rows
four columns and so on. So, k will be that
279
00:51:29,640 --> 00:51:36,640
point initially we assumes that k equals to
1, s equals to 1 and you are interesting to
280
00:51:44,000 --> 00:51:50,280
solve n cross m elements by m cross m
281
00:51:50,280 --> 00:51:57,280
processors in two dimensional mesh. Every
processor contains one element, so you have
282
00:51:57,680 --> 00:52:01,070
n plus m processors every processors
283
00:52:01,070 --> 00:52:08,070
contains one element you are interested to
sort this m square elements k equals to one
284
00:52:09,510 --> 00:52:16,510
first stage s equals to 1 while k is less
than
285
00:52:27,300 --> 00:52:34,300
m.
Assume that there are several sub arrays each
286
00:52:41,860 --> 00:52:48,860
of size k plus k 2 k perform horizontal merge
k plus 2 k, then stage is increase by 1
287
00:53:08,040 --> 00:53:15,040
assume there are several sub arrays each of
size 2 k plus 2 k use vertical merge 2 k plus
288
00:53:32,170 --> 00:53:39,170
2 k 2 increase s by 1. Again, next stage n
289
00:53:45,440 --> 00:53:52,440
k by 2 k, so this is you main algorithms,
so you observe this and this t’s is several
290
00:53:57,200 --> 00:54:04,200
sub arrays bitonic sequence at this stage
is sub
291
00:54:04,780 --> 00:54:11,780
array of size 2 k plus 2 k is a bitonic sequence.
Here, I have not told about the sign function
292
00:54:12,500 --> 00:54:13,630
whether increasing order or
293
00:54:13,630 --> 00:54:17,490
decreasing order, then I will discuss separately.
294
00:54:17,490 --> 00:54:24,490
If it is the case, then what the time complexity
t main algorithm size m cross m number is
295
00:54:32,880 --> 00:54:39,880
of retains. Now, if I start whether 2 a
296
00:54:42,290 --> 00:54:49,290
sequence compute you can start 1 plus 2, then
2 plus 2, then 2 plus 4, then 4 plus 4 different
297
00:54:49,610 --> 00:54:52,050
somehow and so on. Instead of doing
298
00:54:52,050 --> 00:54:59,050
that, let us seeing this way, suppose I get
suppose this is a sorted sequence, this get
299
00:54:59,810 --> 00:55:02,910
a sorted sequence and so on. So, that this
is a
300
00:55:02,910 --> 00:55:09,360
bitonic sequence this is a, another bitonic
sequence and then you have to use horizontal
301
00:55:09,360 --> 00:55:11,360
merge and vertical merge. You will be
302
00:55:11,360 --> 00:55:18,360
getting the total of sorted sequence, suppose
I assume that this is sorted sequence, this
303
00:55:19,080 --> 00:55:21,770
is sorted sequence.
So, this is a bitonic sequence this is sorted
304
00:55:21,770 --> 00:55:26,310
sequence this is sorted sequence this is a
bitonic sequence you call you call horizontal
305
00:55:26,310 --> 00:55:32,140
merge to get a sorted sequence for horizontal
merge to get a sorted sequence point of view.
306
00:55:32,140 --> 00:55:34,060
You get whole bitonic sequence and
307
00:55:34,060 --> 00:55:40,940
vertical merges, so if this is the case, so
can I write here the time complexity for this
308
00:55:40,940 --> 00:55:45,650
is nothing but T R Main algorithms m by 2
309
00:55:45,650 --> 00:55:52,650
cross m by 2 plus t r horizontal merge m by
2 m plus t r vertical merge m comma m. Instead
310
00:56:06,460 --> 00:56:09,440
of looking for bottom line approach, I
311
00:56:09,440 --> 00:56:14,140
am thinking about the top down approach, I
am by some recursive method, I have sorted
312
00:56:14,140 --> 00:56:15,720
this sum sorted this sorted this and
313
00:56:15,720 --> 00:56:20,240
sorted this.
Now, this is a bitonic sequence, so make it
314
00:56:20,240 --> 00:56:27,240
a sorted one which needs horizontal merge
algorithm, so this is the time complexity
315
00:56:30,680 --> 00:56:37,680
simultaneously you do this. Then, you combined
these two using the vertical merge which is
316
00:56:45,290 --> 00:56:52,290
the time needed for doing this is this.
317
00:56:57,910 --> 00:57:04,910
So, this is 8 this is 7 and assume m equals
to 2 to
the power l, what is the solution now T R
318
00:58:43,660 --> 00:58:50,190
M by 4 cos m by 4 plus 7 by 2 m
319
00:58:50,190 --> 00:58:57,190
minus 8 plus 7 m minus 8 m equals to 1 answer
is 0, so up to m equals 2, we have to go that
320
00:59:12,400 --> 00:59:14,050
means l.
321
00:59:14,050 --> 00:59:21,050
What is the answer this is 2 square T R M
1 comma 1, 7, 2 to the power I will write
322
00:59:35,930 --> 00:59:42,930
is it sure, this is 0, this is 0, tell me
the
323
00:59:58,620 --> 01:00:01,360
solution now.
324
01:00:01,360 --> 01:00:08,360
Here, 7 m 1 plus minus 8, l and this is 2
to the power l minus m 2 to the power l minus
325
01:00:28,170 --> 01:00:35,170
1 is 7 m, m minus 1 2 to the power l minus
326
01:00:40,140 --> 01:00:47,140
1 divided by half into 2 minus 8, l, so this
is nothing but 14 m into m minus 1 minus 8
327
01:01:03,640 --> 01:01:05,100
log m.
328
01:01:05,100 --> 01:01:12,100
Now, you have t exchange m main t exchange
main m by 2 m by 2 plus t exchange horizontal
329
01:01:17,500 --> 01:01:21,750
merge m by 2 plus t exchange
330
01:01:21,750 --> 01:01:28,750
vertical merge m comma m. Now, you obtain
3, 3, 3 log m by 2 plus 2 log m what about
331
01:01:54,500 --> 01:02:01,500
this one, 2 log J k 2 log 2 log l square that
332
01:02:13,590 --> 01:02:20,590
is 4 log m this is this gives you what three
log m three log m plus two 5 plus 9 log m
333
01:02:35,170 --> 01:02:51,530
t e m m by 2 m by 2 9 log m minus 3. So,
334
01:02:51,690 --> 01:02:58,690
what is the solution for this 9 log m, tell
me minus 3 plus 9 log m by 2 minus 3 plus
335
01:03:14,110 --> 01:03:21,110
9 log m 4 minus 3, 9 log m.
So, it is 14 m minus 1 minus 8 log m, what
336
01:04:10,720 --> 01:04:17,720
about this one, what is time still it is away,
tell me this is this expansion. Then, what
337
01:04:45,530 --> 01:04:46,250
is
338
01:04:46,250 --> 01:04:53,250
the answer many log m 9 log m. So, log squared
m minus 3 times log m
minus first one is minus 9, second one is
339
01:05:25,360 --> 01:05:32,360
what 18, so I
340
01:05:33,540 --> 01:05:40,540
should take 9 out 1 plus 2 plus l minus 1,
so I get 9 log square m minus 3 log m minus
341
01:05:56,510 --> 01:06:03,510
9 log m log m minus 1 divided by 2.
342
01:06:09,850 --> 01:06:16,850
So, you get four point 5 log square m
plus 7.5 minus is there no 4.5 plus 1.5 log
m.
343
01:06:33,500 --> 01:06:40,500
Now, tell what is the number of comparisons
one is first one is log J right this perform
344
01:06:54,470 --> 01:07:01,470
is log J, log m plus first one, Log m by 2
345
01:07:06,050 --> 01:07:13,050
minus log m, Log m by 2 minus log m. What
is the formula, Log J minus log k, Log J minus
346
01:07:15,730 --> 01:07:17,710
Log k minus log k minus log J minus
347
01:07:17,710 --> 01:07:24,710
log k minus this is minus J plus log k minus
1 and what about vertical merge log J log
348
01:07:42,880 --> 01:07:49,880
J plus log k. So, this keeps you 2, 3, 3.5,
3,
349
01:07:55,369 --> 01:08:02,369
4, 1 , 2 , 3, 4, 4 log m minus 2 minus 2 plus
4 times log m by 2 minus 2, 4 times log m
350
01:08:22,150 --> 01:08:28,270
by 2 to the power n minus 1 minus 2. How
351
01:08:28,270 --> 01:08:35,270
many log m s 4 into log m into log m because
there are log m 2 log m minus 2 times log
352
01:08:43,009 --> 01:08:50,009
m plus or minus 1 plus 2 plus l minus 1
353
01:09:03,830 --> 01:09:10,830
into 4.
So, 4 times log square m minus 2 log m minus
354
01:09:18,000 --> 01:09:25,000
4 times log m log m minus 1 divided by 2,
so 2 log square m only right such simple
355
01:09:36,960 --> 01:09:43,960
one good. So, this is about the number of
comparisons, you need now the sign thing only
356
01:09:46,270 --> 01:09:50,839
because you have can you give 2, 3
357
01:09:50,839 --> 01:09:55,800
minutes. So, I am yet to cover in the next
class, I will cover the sign function.