1
00:00:16,129 --> 00:00:23,129
So, in the last class we were discussing about
the medium pair algorithm, let in the medium
2
00:00:25,119 --> 00:00:32,119
pair idea is you have to sequence and you
have to find out the medium pair. Such through
3
00:00:35,620 --> 00:00:42,620
that the devise exactly two equal half so,
that next time this is done by one person.
4
00:00:44,050 --> 00:00:50,150
And next time I have applied two person two
divide one person is to divide this part in
5
00:00:50,150 --> 00:00:57,150
two parts and this parts into two part and
the size become same with condition is the
6
00:00:57,570 --> 00:01:01,409
size become same.
7
00:01:01,409 --> 00:01:08,320
And all this elements will be smaller than
these elements. This element would be smaller
8
00:01:08,320 --> 00:01:15,320
than this element now, I can apply n process
two merge is sub part and they will take the
9
00:01:19,909 --> 00:01:26,909
same amount of time and then there is no need
of concurrent read part. So, only if I do
10
00:01:29,429 --> 00:01:36,429
this partition that will take care so, the
issue is how to divide or how to create the
11
00:01:40,420 --> 00:01:47,420
medium pair. Initially this process is like
this initially, I will take the middle value
12
00:01:50,499 --> 00:01:57,499
so, I can assume that these two elements are
the probable candidate for my median pair.
13
00:01:57,770 --> 00:02:04,770
Now if this is the case you also know this
is two points because this is n by 2 this
14
00:02:08,530 --> 00:02:15,400
is m by 2.
So, take some of this then it becomes one
15
00:02:15,400 --> 00:02:22,400
of them will be n plus m divided by 2 that
medium means that is the elements. There is
16
00:02:23,990 --> 00:02:30,990
a probable candidate but, as I told this cannot
be a probable candidate for the median now,
17
00:02:33,620 --> 00:02:40,620
what it does? He checks is there any element
in this zone which is larger this element
18
00:02:43,810 --> 00:02:50,810
over is there any element of this zone which
is larger than this element.
19
00:02:52,400 --> 00:02:59,400
Suppose, there exit one element here which
is larger than this element. Suppose, what
20
00:03:00,130 --> 00:03:07,130
it means that all this element should be smaller
than this element, there exit one element
21
00:03:10,760 --> 00:03:17,760
one element here which is, if I find that
this is smaller than this element, then all
22
00:03:17,850 --> 00:03:24,340
this element should be smaller than this element.
What it means suppose, this is k then n by
23
00:03:24,340 --> 00:03:31,340
2 class m by 2 class k that many elements
smaller than this element. So, this cannot
24
00:03:32,740 --> 00:03:39,740
be the median element. If you want to make
this the median element you have to find out
25
00:03:41,480 --> 00:03:45,870
median element. Once this has to be shifted
by smoothing has many house you have shifted
26
00:03:45,870 --> 00:03:52,870
this side. So, you have to shifted by k house
this side so, what happens that now probable
27
00:03:54,310 --> 00:04:01,310
candidates is that this and this are the member
of the so, we if increase this side that should
28
00:04:01,860 --> 00:04:08,510
be decreased this side. So, that m plus n
m by n m by 2 plus n by 2 that relationship
29
00:04:08,510 --> 00:04:11,620
is maintain.
30
00:04:11,620 --> 00:04:18,620
Now, since it is shorter order so, you can
use the binary search to find it out. So,
31
00:04:24,759 --> 00:04:31,759
you have to find out the median pair suppose,
you have a equals so, as usual you have low
32
00:04:37,160 --> 00:04:44,160
is one high is your m low in that sub b is
1 and height of b is your n than number of
33
00:04:56,680 --> 00:05:03,680
elements in a is m number of elements in b
is your n. So, in a o points to the total
34
00:05:11,370 --> 00:05:18,370
number of elements you are considering for
finding the median para n a in this n a gives
35
00:05:23,410 --> 00:05:29,840
you the number of elements in the n a which
you are considering for finding the median
36
00:05:29,840 --> 00:05:36,840
pair element. And n b gives to the total number
of elements in the array b which are under
37
00:05:37,030 --> 00:05:40,500
consideration for median pair.
38
00:05:40,500 --> 00:05:46,980
Now, this time doing this first time I am
considering this one second time my searching
39
00:05:46,980 --> 00:05:53,110
zone may be this one or this side because
the binary searching be halfing out the time.
40
00:05:53,110 --> 00:06:00,110
You know there may be a terminal condition.
What is that while n a is greater than 1 and
41
00:06:07,870 --> 00:06:14,870
n b is greater than 1. Do we have to find
out the middle element middle? Middle element
42
00:06:26,060 --> 00:06:33,060
is low of a plus H a minus L a minus 1 divided
by 2 v is a at this equation you will be able
43
00:06:54,080 --> 00:07:01,080
to discord some part. Suppose, I find out
this element is smaller than this you have
44
00:07:07,740 --> 00:07:11,600
to shift this axis’s searching that will
be reduced.
45
00:07:11,600 --> 00:07:17,430
Now, as we do in the case of binary search,
what you do in the binary search that you
46
00:07:17,430 --> 00:07:23,460
search here if it is larger than you. Go to
this side and this part is reduce you have
47
00:07:23,460 --> 00:07:28,540
discarding same this would be here you are,
you want to discards certain parts to find
48
00:07:28,540 --> 00:07:35,540
out the appropriate pair of elements So, new
n a will be next time it will be half and
49
00:07:39,850 --> 00:07:46,850
new n b is also n b by half and your amount
will be able to discard is minimum of n a
50
00:07:54,790 --> 00:08:01,790
n n b will discuss two example this one I
think, I should not change n a n b now.
51
00:08:07,199 --> 00:08:14,199
Then i may be little problem here you have
put it by 2 by 2 and then you put n a is equal
52
00:08:16,880 --> 00:08:23,880
to n a minus w n b is equal 2 n b minus. Where
there no guaranty otherwise difference is
53
00:08:31,860 --> 00:08:38,860
that see half if I write first n equals to
n a by two parts. If I right n a is equal
54
00:08:42,019 --> 00:08:49,019
to n a by 2 and n b is equal to n b by 2 and
w defined that minimum of this 2. What it
55
00:08:57,010 --> 00:09:04,010
and then n a size well be reduce by I have
already reduce by size by half but, this side
56
00:09:05,710 --> 00:09:12,710
there is no guaranty I can reduce by half
exactly. I can reduce maximum this side here.
57
00:09:13,270 --> 00:09:20,270
Not more than that because i have to get the
guaranty because I have told that this is
58
00:09:20,790 --> 00:09:27,649
not a probable candidate. So, that guaranty
also you have taken here. So, you got n a
59
00:09:27,649 --> 00:09:34,649
now if you find that a u is greater than b
u than a u if, a u is greater than b v what
60
00:09:45,460 --> 00:09:52,460
it means that element I have to find out the
element from this zone a u is a u greater
61
00:09:55,440 --> 00:10:02,440
so, I have to find out the element from this
zone sorry element from this zone and this
62
00:10:02,990 --> 00:10:09,990
side is your b v so I have to find out this
side a u if find greater than b v that means
63
00:10:13,600 --> 00:10:16,990
the median pair must be lining from a v here.
64
00:10:16,990 --> 00:10:23,990
And from here so, that means in this zone
means height should be high or high in that
65
00:10:26,560 --> 00:10:33,560
should be reduce. So, your h a
becomes h a minus h a becomes u minus 1 and
l b becomes v plus 1. So, h a becomes this
66
00:11:07,070 --> 00:11:14,070
1 and will becomes this 1. Else is the reveres
1 l a becomes v plus 1 g b becomes nor be
67
00:11:22,570 --> 00:11:29,570
u plus 1 and this is v minus 1. h a becomes
u minus 1 l b becomes v plus 1 l a becomes
68
00:11:39,550 --> 00:11:43,779
u plus 1 h b becomes v minus 1.
69
00:11:43,779 --> 00:11:50,779
So, once this will be interested till there
exit at list 2 elements in n a and n b so,
70
00:11:51,550 --> 00:11:58,550
when it is 1 of the median pairs you will
be getting 1 you will be getting the u and
71
00:12:03,120 --> 00:12:10,120
v. So, if you get some u and some b this is
u and this is b. But, you have to know that
72
00:12:16,140 --> 00:12:22,670
this may not give as you through an example
you have seen this is the most probable candidate
73
00:12:22,670 --> 00:12:29,670
to be the median pair. So, what it has been
observed because of that u minus 1 and v plus
74
00:12:35,810 --> 00:12:42,810
1, that this are the three probable candidates
can be the member of your median pair.
75
00:12:55,080 --> 00:13:02,080
So, consider a u minus 1 a u and a u plus
1 and b b minus 1 b v and b v plus 1. So,
76
00:13:12,980 --> 00:13:19,980
how many pair will be getting with refers
to this will get 3 you will get 9 and you
77
00:13:32,589 --> 00:13:39,589
select one which satisfy your definition of
median pair that can be done in constant 10.
78
00:13:41,610 --> 00:13:48,610
Now, you know the definition of median pair
so, nine element you select for this element
79
00:13:50,610 --> 00:13:57,610
whether he is the middle element or not all
for this whether, he is the middle element
80
00:14:00,230 --> 00:14:07,230
or not that is the thing 9th element whatever
you perform the rotate constant amount of
81
00:14:07,260 --> 00:14:14,260
time right so, you have form the nine element
you have to get the 5th element. For example
82
00:14:21,160 --> 00:14:25,870
we have that summation of that means median.
83
00:14:25,870 --> 00:14:32,870
Let us think first this three elements 3 7
11 4 6 and 8. So, you get 3 4 3 6 3 8 3 4
84
00:14:46,120 --> 00:14:53,120
7 6 7 8 11 4 11 6 11 8 this are the nine pairs
should be get it. Now, which one is median
85
00:15:01,200 --> 00:15:08,200
pair for this 9 3 4 6 7 8 this so, 7 is your
median element agreed. Yes 6 also possible
86
00:15:21,360 --> 00:15:28,360
middle elements so, one possible candidate
is this one and another possible candidate
87
00:15:28,769 --> 00:15:35,769
is these one another possible is this one
another candidates possible. This 1 6 8 6
88
00:15:40,370 --> 00:15:47,370
11 cannot be a possible candidate.
No because 6 7 is line there right this are
89
00:15:50,190 --> 00:15:57,190
the 4 yes 7 4 is, If 3 6 also not possible
candidate 3 6 is also not a possible candidate
90
00:16:05,389 --> 00:16:12,389
4 7 6 7 7 8. All 7 4 7 and 6 4 7 7 4 what
is the definition we may one of them is median
91
00:16:28,930 --> 00:16:29,690
and another element is.
92
00:16:29,690 --> 00:16:36,690
Yes other element is either smaller than this
element or just higher than this element so,
93
00:16:49,560 --> 00:16:56,560
if 7 is median pair median element then all
the element so, 6 is a probable candidate
94
00:17:02,279 --> 00:17:09,279
and 7 8 is probable candidate in the case
6 is a middle element. 6 3 is possible and
95
00:17:15,639 --> 00:17:22,639
6 7 is possible so, not 7 4 from the definition
now, we will be selecting the one whose some
96
00:17:25,890 --> 00:17:32,890
of the index is the smallest. So, here it
is 1 2 3 so, this will be the 3 6 actually
97
00:17:37,570 --> 00:17:44,230
3 6 is the your returned.
Sir why should be consider the element after
98
00:17:44,230 --> 00:17:51,230
larger than the minimum if you’re taking
the minimum some of the index? Yes. Element
99
00:17:51,320 --> 00:17:58,320
data’s smaller than the median will have
a smaller index and larger index. No see median
100
00:17:58,870 --> 00:18:02,370
pair definition first let, us some probable
defined definition was made like that one
101
00:18:02,370 --> 00:18:09,370
of this two element will be the median element
the other element of the other sequence is
102
00:18:12,190 --> 00:18:19,190
that element we is the either the largest
element smaller than the median element or
103
00:18:22,419 --> 00:18:28,120
the smallest element larger the median element.
And if you get and more than 1 return than
104
00:18:28,120 --> 00:18:35,120
we select the one whose some of indices is
minimum there is the definition depart right
105
00:18:36,740 --> 00:18:42,470
based on that only here finding this.
106
00:18:42,470 --> 00:18:49,470
Now, this can be done in constant amount of
time because my pear and manipulate all this
107
00:18:55,210 --> 00:19:02,210
thing agree and here theoretically, that every
time we are dividing into half half half half
108
00:19:03,150 --> 00:19:09,120
in reality that is different but, theoretically
that there of equal size and very time you
109
00:19:09,120 --> 00:19:16,120
are reducing by half. So, log after log nitration’s
i must be able to come here to six constant
110
00:19:23,220 --> 00:19:30,220
of time. So, complicity of this algorithm
becomes longer or long of maximum of n a n
111
00:19:39,179 --> 00:19:44,730
b or n a n b means your n n m.
112
00:19:44,730 --> 00:19:51,730
So, let us consider one example I think through
that we will able to we so, regulate is 1
113
00:19:56,790 --> 00:20:03,790
n h a is your 8 initially, l b is 1 h b is
your 6 n a is your 8 n b is 6 that this is
114
00:21:09,410 --> 00:21:16,410
the first nitration u is 1 plus six by 2 say
this 4 v is equal to 1 plus 4 by 2 this w
115
00:21:37,250 --> 00:21:44,250
n a modified is 5 n b is 3. If a u a four
which is a is greater than a 3 b 3, b 3 is
116
00:22:30,450 --> 00:22:37,450
what ten answer is no if it is no so, this
is compact if it is no L a becomes u plus
117
00:23:02,419 --> 00:23:05,110
1 minus.
118
00:23:05,110 --> 00:23:12,110
5 an h b is 2 now, u becomes 1 plus 8 minus
5 minus 1 so, divide by 2 if this l is 5 here
119
00:23:37,960 --> 00:23:44,960
5 plus 1 it is 6 v is 1 plus 0 so, b i1 w
is 1 so, n a is 4 n b is 1 than a 6 is 1 13
120
00:24:38,220 --> 00:24:45,220
is it greater than it is less than or greater
than b. What is b b 1 is 2 it is then h a
121
00:25:07,919 --> 00:25:14,919
h to be updated h a is 5 minus 5 and l b is
2. Now u is l a la still 5 plus 0, which is
122
00:25:36,669 --> 00:25:43,669
5 5 minus 5 0 so, it is 0 you have take this
index so, it is 5 u is 5 v is this is actually,
123
00:26:08,360 --> 00:26:15,360
v minus 5 minus 1. 5 minus 5 is 0 minus one
by 2 is 0 to take the low index upper index
124
00:26:29,190 --> 00:26:36,190
on to be this, b is what? Now we have to take
it 0 because we have in this a part of it
125
00:26:40,760 --> 00:26:47,760
say b is what now, b is l l b 2 plus 2 minus.
So, this is also 0 so, this is 2 w is what
126
00:27:08,950 --> 00:27:15,950
n a. So, w is 1 n a is 3 n b is 1 now, if
u 5 a 5 what 9 greater than equals to 6 answer
127
00:27:21,059 --> 00:27:28,059
is yes if yes than h a is 4 and l b is 3.
Student: Sir in the last second stage 5 w
128
00:27:36,159 --> 00:27:43,159
is 1 if 2 may com 5 com.
129
00:27:52,990 --> 00:27:59,990
Minimum of n a by 2 n b by 2 so, here we are
written well is a 5 and b 2 because now, n
130
00:28:17,429 --> 00:28:24,429
a has come n b is come greater than equals
to 1 so, it will stop so, basically you get
131
00:28:30,150 --> 00:28:37,150
the sequence this is 1 2 3 4 5 so, 8 9 13
and 2 6 10 this are from the a sequence you
132
00:28:51,110 --> 00:28:58,110
get this from b sequence you get this and
you have median pair this lines here. Let,
133
00:29:01,409 --> 00:29:08,409
us see 1 2 1 2 3 4 6 7 8 totally 14 elements,
after find out the 7th element 12 3 4 5 6
134
00:29:18,929 --> 00:29:25,929
7 so, this type of elements should be there
135
00:29:27,539 --> 00:29:34,539
So, it will consider1 of the 2 6 yes 2 6 8
6 elements so, 3rd or 4th element by this
136
00:29:44,840 --> 00:29:51,840
or this median. So, this form either here
it will be possible will be getting from there
137
00:29:57,600 --> 00:30:04,600
8 and 9 are the median pair. Median element
so, and it will be selected now if I find
138
00:30:08,059 --> 00:30:15,059
what are the probable candidate tell me from
here median element one can be 8 if you 8
139
00:30:17,820 --> 00:30:24,820
than it can be 2 8 or 8 6 if it is 9.
140
00:30:26,490 --> 00:30:33,490
If it is 8 than how 2 you may 6 8 minimum
element, yes 8 6 another one is 8 and 10 concurrent
141
00:30:41,960 --> 00:30:48,960
if is 9, 9 6 9 10 and the written will be
1 which is having the minimum index. Either
142
00:30:52,799 --> 00:30:59,799
this 1 8 6 it is the one of the element is
the middle one so, there is the idea now this
143
00:31:05,419 --> 00:31:12,419
here right and what I here he use the idea
of binary research 1 2 so, two arrays in such
144
00:31:17,590 --> 00:31:24,590
way that if this moves this side the other
point moves in this side that is the only
145
00:31:25,149 --> 00:31:31,659
thing this is not a very big achievement but,
we observe through that where is w problem
146
00:31:31,659 --> 00:31:38,659
can be solved there is the only thing. What
is the array once I move the point from here
147
00:31:41,330 --> 00:31:48,330
to here this point will move from here to
here so, that n by 2 half I to get a median
148
00:31:50,750 --> 00:31:57,750
pair. So, median element must be 3 so, that
properties maintain so, once I know this median
149
00:31:58,590 --> 00:32:04,279
pair and you observe this median pair is a
sequential algorithm.
150
00:32:04,279 --> 00:32:11,279
We got that you use the pair algorithm on
this part. So, once I know this sequential
151
00:32:11,360 --> 00:32:17,830
algorithm for finding the median pair this
can be use for here will be rotating. So,
152
00:32:17,830 --> 00:32:24,830
if the first iteration suppose, if we have
two sequence in the first iteration I use
153
00:32:25,529 --> 00:32:31,830
one person to find the median pair in the
second iteration I use 2 person to find out
154
00:32:31,830 --> 00:32:38,830
the median pair and 3rd you have use 4 person
to find the median pairs and so on.
155
00:32:39,110 --> 00:32:46,110
And we divide this pair such way that one
element is the middle element the other element
156
00:32:46,370 --> 00:32:53,370
is selected in such way that all this elements
are smaller than this elements. So, that the
157
00:32:53,380 --> 00:33:00,380
properties is maintain than this cluster is
smaller than cluster on so, on it is so, e
158
00:33:07,850 --> 00:33:14,850
r e w merge e r e w merge processor p one
receives. So, one m one n what it means that
159
00:33:58,690 --> 00:34:05,690
he grade the first index of a sequence last
index of a sequence first index of b sequence
160
00:34:11,039 --> 00:34:18,039
last index of now, for j is equal to 1 2 log
n is the total number of processor do for
161
00:34:32,549 --> 00:34:39,549
I is equal to 1 2 to the power two to the
power j minus 1 l 4 l m.
162
00:35:01,039 --> 00:35:08,039
So, what I am telling first time one processor,
I am accurating second time two person and
163
00:35:13,209 --> 00:35:20,209
so on p i get a b c d, a b c d means a is
the first index b is the second index of the
164
00:35:26,309 --> 00:35:33,309
first sequence. First index and last index
of second sequence p i calls
median pair a now, if a x is median then if
165
00:36:18,859 --> 00:36:25,859
a x is median then I will be trans pitting
from here to here and here to here to the
166
00:36:35,200 --> 00:36:42,200
next processor p 1 and here to here and here
to here to the other processor so that next
167
00:36:44,089 --> 00:36:51,089
iteration he gets this bonds and he divides.
So, from here to here this I have to said
168
00:36:54,609 --> 00:37:01,609
the index x. So, let us assume that p 1 is
the starting index p 1 p 1 is x and q 1 is
169
00:37:08,009 --> 00:37:13,839
the starting index for the next processor
which is x plus 1.
170
00:37:13,839 --> 00:37:20,839
Up to this for the first processor and from
here onwards to the next processor and here
171
00:37:28,930 --> 00:37:35,930
you have to find out now, if a x is less than
b y if a x is less than b y then 1 b y is
172
00:37:48,069 --> 00:37:55,069
the larger than this that means this element
will be smaller than a x this is the smallest
173
00:37:55,160 --> 00:38:02,160
element larger than this. So, up to this I
have to send it to first processor so, p 2
174
00:38:05,769 --> 00:38:12,769
is y minus 1 and q 2 is y else p 2 is y and
q 2 is y plus 1 so, i got p 1 i got p 2 i
175
00:38:28,059 --> 00:38:32,209
got q 1 i got q 2.
176
00:38:32,209 --> 00:38:39,209
Else b y is the median. So, if b y is the
median p 2 is your y q 2 is your y plus 1
177
00:39:02,890 --> 00:39:09,890
if b y is greater than b y is less than x
than p 1 is your x minus 1 q 1 is your x else
178
00:39:24,859 --> 00:39:31,859
p 1 is your x q 1 is your x plus 1. There
is the p got it now next is i have to board
179
00:39:42,599 --> 00:39:49,599
cast it p i should communicate to the next
processor p 1 should send the value 2 p 1
180
00:39:55,559 --> 00:40:02,559
and should a this part and this part so, next
iteration you observed so, first is p 1 does
181
00:40:05,229 --> 00:40:12,229
the work next 1 p 1 and p 2 than p 1 p 2 p
3 p 4 so, p 2 sends the information to this
182
00:40:16,150 --> 00:40:21,089
p 1 sends this information to this.
183
00:40:21,089 --> 00:40:28,089
Next time p 1 p 2 p 3 p 4 p 5 p 6 p 7 p 8
8 processor. We have to transmit this that
184
00:40:38,769 --> 00:40:45,769
is the way you would broadcasting. So, if
i in p 3 p 3 broadcast the direct to which
185
00:40:46,579 --> 00:40:53,579
p 5 and p 6 how to get that p i sends a coma
p 1 than p 2 coma to the last index p 1 c
186
00:42:05,489 --> 00:42:12,489
is the last index defined. Which is p 2 an
first index just immediate this is x plus
187
00:42:18,309 --> 00:42:25,140
1 to the last index is b and because it was
initially a b now will be send it a p 1 and
188
00:42:25,140 --> 00:42:32,140
p 2 and q 1 q 1 2 b l q 1 to b p 1 to b yes
or no similarly, c p 2 and this side q to
189
00:42:52,039 --> 00:42:59,039
2 should be q 2 to send 2 p 2 i minus 1 2
i so, p is send p i send to this next iteration
190
00:43:06,789 --> 00:43:13,789
p i p i is nothing but, the new p i gets this
4 parameters he compute this and so on.
191
00:43:14,509 --> 00:43:21,509
So after log iteration a b c d what is it
is a starting in the p i, a b c d p i is got
192
00:43:35,440 --> 00:43:42,440
this part this is the sequence and this is
the b sequence. Now, you have to merge it
193
00:43:48,640 --> 00:43:55,640
so, you need to compute in the c sequence.
What is a starting index and the n in index
194
00:44:04,699 --> 00:44:11,699
yes or know now, how to get the starting index
is every processor is doing now, you are dividing
195
00:44:14,609 --> 00:44:21,609
equal part every processor is having that
much size. Because equal part so, there if
196
00:44:28,140 --> 00:44:35,140
i multiplied by n than i get m plus n total
number of elements so every processor is m
197
00:44:35,930 --> 00:44:42,930
plus n divided by n block. So, i f processor
starting index will be if it is w it is this
198
00:44:53,609 --> 00:44:57,180
is the starting index.
199
00:44:57,180 --> 00:45:04,180
And what is your n index, n index is minimum
of i times m plus n divided by n or m plus
200
00:45:15,089 --> 00:45:22,089
n because, last 1 last 1 may not be exactly
r m plus n divided by n last 1 may not be
201
00:45:25,359 --> 00:45:32,089
exactly that is size. So, that will be little
1 2 be because you are dividing by n so, this
202
00:45:32,089 --> 00:45:39,089
i maximum index is m plus n so, p i merge
sequence uses sequential merge algorithm to
203
00:45:51,019 --> 00:45:58,019
merge a a coma b b c coma d to store in c
w coma z merge with and store it in c w coma
204
00:46:23,940 --> 00:46:24,479
z.
205
00:46:24,479 --> 00:46:31,479
Now, if i have compute the time complexity
this takes constant amount of time this take
206
00:46:33,940 --> 00:46:40,940
constant amount of time this also takes constant
amount of time now, what is the time needed
207
00:46:47,869 --> 00:46:54,869
here. What is the log algorithm so, at the
ith at the j f s stage at the j f s stage?
208
00:47:15,609 --> 00:47:22,609
What is the sign 2 1 to log n th at the j
fs stage at the first stage if the first it
209
00:47:25,109 --> 00:47:32,109
is the m plus n. So, time needs log of m plus
n in the second stage m plus n divided by
210
00:47:38,449 --> 00:47:39,479
2.
211
00:47:39,479 --> 00:47:46,479
At the j fs stage it is log of m plus n divided
by 2 to the power j minus 1 agreed. First
212
00:47:51,170 --> 00:47:58,170
stage it is m plus n second class there is
a m plus n divided by 2 and so on agreed.
213
00:47:58,219 --> 00:48:05,219
So, this is your inside the loop but, summation
if i take than it becomes what so, this becomes
214
00:48:08,589 --> 00:48:15,589
whole algorithm becomes order log capital
n log m plus n. What about this 1 sequential
215
00:48:23,819 --> 00:48:30,819
merge log it takes m plus n divided by n because
if that is the maximum size your m plus n
216
00:49:09,539 --> 00:49:16,539
divided by n because if that is the maximum
size you have agreed.
217
00:49:17,699 --> 00:49:24,699
So, the total time complexity becomes t m
is or not t m t m n because order log capital
218
00:49:34,449 --> 00:49:41,449
n log m plus n plus m plus n by n now, if
m equals to n than this becomes order log
219
00:49:55,469 --> 00:50:02,469
n log small n plus n by n. So, the cost becomes
n log n log n plus n so, it is cost optimal
220
00:50:26,609 --> 00:50:33,609
if
small n is equal to order n log n log n. That
is if n is less than equal to n by log square
221
00:51:03,880 --> 00:51:21,100
n that is if n less than equals to n by log
square n. So, is cost optimal if is algorithm
222
00:51:31,520 --> 00:51:40,720
so, we have discussed the c r e w merge in
algorithm c r e w merge in algorithm. So,
223
00:51:40,780 --> 00:51:53,100
in the next class to discuss out line short
on c r c w and c r e r e w equals also c r c w.