1
00:00:31,330 --> 00:00:52,830
Good morning today we will discussing about
Odd-Even Merging Sorting network and since
2
00:00:52,830 --> 00:01:15,310
you do not know anything about odd even merging
so first we will be discussing odd even merging
3
00:01:15,310 --> 00:01:28,390
technique then we will be discussing odd even
merging network .
4
00:01:28,390 --> 00:01:56,160
Let us assume the term A and B be the two
sorted sequence and problem is to merge these
5
00:01:56,160 --> 00:02:26,920
two sorted sequence in odd even merging technique.
6
00:02:26,920 --> 00:03:20,010
What it does that it forms A 1 A 2 are the
two disjoint sets A1 contains the elements
7
00:03:20,010 --> 00:03:51,540
which are audit checks even index similarly
is the case of B now by odd even merging technique
8
00:03:51,540 --> 00:04:26,490
recursively merge A 1 B1 and similarly A2
B2 we have sequence A sequence B now you get
9
00:04:26,490 --> 00:04:40,930
A 1 B1 A2 B2 right you have the odd even merging
technique you are defining same thing you
10
00:04:40,930 --> 00:04:45,130
are defining odd even merging technique recursively
.
11
00:04:45,130 --> 00:05:04,960
Now you get the sequence A and sequence B
and D sequence you get the E sequence recursively
12
00:05:04,960 --> 00:06:04,699
you have done the odd even merge of this you
get this sequence .So let it be D now if it
13
00:06:04,699 --> 00:06:23,029
is the case then can I draw the conclusion
because minimum is either A 1 or B 1 right
14
00:06:23,029 --> 00:06:35,319
so D1 is the minimum and can I say that A1
is the maximum right now the second thing
15
00:06:35,319 --> 00:06:48,599
is who is the second element any idea has
been taken.
16
00:06:48,599 --> 00:07:11,069
So let us define C1 is d1 c2i is minimum or
d i+1and c2n the problem is given and two
17
00:07:11,069 --> 00:07:34,919
sorted sequences I have taken the odd sequences
which form A1 what sequence of B gives you
18
00:07:34,919 --> 00:07:50,020
B 1 even the index elements form A2 and recursively
you are merging A 1 B 1 you get the sequence
19
00:07:50,020 --> 00:07:57,370
d 1 d2 d n .
Similarly you get the sequence e 1 to en now
20
00:07:57,370 --> 00:08:19,639
C 1 is B 1 C 2 n is N and c 2i is defined
by the minimum of d i+1 e i and now we have
21
00:08:19,639 --> 00:08:39,030
to prove that this gives the sorted sequence
that is the only thing so this obviously we
22
00:08:39,030 --> 00:08:42,870
do not have to prove right .
23
00:08:42,870 --> 00:09:05,210
Now let us consider the sub sequence of d
that is d 1 d 2 d i+1 let us consider and
24
00:09:05,210 --> 00:09:19,620
you will find it satisfies the criteria because
this is recursively sorted it satisfies this
25
00:09:19,620 --> 00:09:41,220
now let us assume that k of them belong to
A sequence right because d 1 d 2 d i+1 this
26
00:09:41,220 --> 00:09:55,950
sequence is obtained from odd index subsequence
of A and odd index subsequence of B so either
27
00:09:55,950 --> 00:10:06,910
we can assume the k of them belong to A sequence
what is here is A1 sequence sorry A1 of them
28
00:10:06,910 --> 00:10:21,690
then does it imply that i+1-k of them belongs
to B1 sequence.
29
00:10:21,690 --> 00:10:37,940
Because total number of elements yes k of
this is adoption and k of them belong to this
30
00:10:37,940 --> 00:10:50,690
it indicates that i+1-k of them belongs to
B1 sequence now what does it mean be that
31
00:10:50,690 --> 00:11:03,200
K of them belong to A1 sequence means that
a1,a3 a5 and so on and you got what is the
32
00:11:03,200 --> 00:11:28,170
index of this 2k + 1 is it okay if it is the
case then can I write how many of them what
33
00:11:28,170 --> 00:11:53,100
should we write belong to original A sequence
see how many elements are here k elements
34
00:11:53,100 --> 00:12:06,170
right so are you sure 100% I have three elements
here.
35
00:12:06,170 --> 00:12:37,930
How many elements are here a 1 a 3 and a 5
under you have three elements in between how
36
00:12:37,930 --> 00:12:56,120
many elements are there how you are telling
k how are they linked this one this part I
37
00:12:56,120 --> 00:13:25,580
am taking that I have what index element and
how many elements so I can write it is k-1
38
00:13:25,580 --> 00:13:37,240
so what is that 2 k-1 because k-1 even index
elements k-1 even in these elements key elements
39
00:13:37,240 --> 00:13:58,210
of odd index elements so total 2k - 1 elements
and they are because this is sorted agreed
40
00:13:58,210 --> 00:14:09,410
yes now if it is the case.
So can you tell me from here how many elements
41
00:14:09,410 --> 00:14:23,490
of that belonging to B sequence how many or
index elements i+1-k and how many even index
42
00:14:23,490 --> 00:14:39,850
elements i-k so what I the total number of
elements so 2i+1- 2 k right that elements
43
00:14:39,850 --> 00:14:54,890
belonging to B so what does it mean be 2 k
belonging to a sequence which is = d i+1 that
44
00:14:54,890 --> 00:15:22,960
many elements will change = d i +1 is
it okay what will did belonging to A1 sequence
45
00:15:22,960 --> 00:15:36,730
it will be i+1-k elements belonging to sequence
it indicates the 2k-1 elements belonging to
46
00:15:36,730 --> 00:15:53,520
sequence it indicates and if I add this two.
What I get 2y elements belonging to A and
47
00:15:53,520 --> 00:16:18,930
B = d i+1 now if c is the sorted sequence
so can I write C2i = d i+1 because by combining
48
00:16:18,930 --> 00:16:36,860
these two I got 2i elements belonging to the
combined A and B = d i+1 similarly you can
49
00:16:36,860 --> 00:16:40,100
show C2i = e i .
]
50
00:16:40,100 --> 00:17:06,880
So let us consider sub sequence C 1 C 2 C
3 C 2i+ 1 now this is sorted sequence so I
51
00:17:06,880 --> 00:17:27,130
can write this is equal to this into a sequence
so let us assume that k of them belonging
52
00:17:27,130 --> 00:17:43,730
to A sequence
so I can write this is a dumb hit I can write
53
00:17:43,730 --> 00:18:03,269
2i+1-k of them belonging to B sequence because
now can you tell me how many of them in that
54
00:18:03,269 --> 00:18:46,619
case from here of them belonging to A1 sequence
so this is a sub sequence so how many of them
55
00:18:46,619 --> 00:19:05,740
belonging to A1 if it is odd so you will be
writing k/2 of them belonging to A1 and if
56
00:19:05,740 --> 00:19:22,549
k is even else k+1/2 now if it is the case
from here can I write something how many of
57
00:19:22,549 --> 00:19:48,190
them belonging to B1 sequence .
Now assume that k is even otherwise if k is
58
00:19:48,190 --> 00:20:02,730
odd you have to do little manipulation that
i +1-k/2 in both the case if I gave you tell
59
00:20:02,730 --> 00:20:33,340
me if I add these two I get i+1 so it k/2
of them belonging to a 1 sub sequence right
60
00:20:33,340 --> 00:20:48,450
which is = C 2i+ 1 right here k/2 of them
belonging to A sequence up to this so I can
61
00:20:48,450 --> 00:21:13,289
write C 2i+ 1 yes similarly I can write this
as = C 2i+ 1 that means i+1 of them belonging
62
00:21:13,289 --> 00:21:34,809
to A1UB1 or the merge of A 1 B 1 = C 2i+ 1
agree and this gives you the condition d i+1
63
00:21:34,809 --> 00:21:54,590
= C 2i+ 1 because i+1 elements of this one
so I can write d i+1 .
64
00:21:54,590 --> 00:22:13,159
Similarly you can write e i = C 2i+ 1 so combining
these four equations you can write that C
65
00:22:13,159 --> 00:22:26,690
2i = C 2i+ 1 is minimum of d i+1, e i and
C 2i+ 1 is maximum of d i+1,e i so combining
66
00:22:26,690 --> 00:22:41,539
this equation along with so the arguments
take correctly merges two sequence a and b
67
00:22:41,539 --> 00:22:55,409
and this idea can be used to define the merging
network .
68
00:22:55,409 --> 00:23:13,399
You have suppose n elements which are a 1
,a2 ,a3, a4 and b1 ,b2, b3, b4 and you have
69
00:23:13,399 --> 00:23:26,649
network called n/2 x n/2 odd even merging
network here it is odd index and you get the
70
00:23:26,649 --> 00:23:54,830
recursive technique you have d1 ,d2, d3 ,d4
....d n and you have e1, e2, e3 ....en and
71
00:23:54,830 --> 00:24:42,019
so here d1 is your c1 and then e2 is compared
with d1 you get c2 and d3 is compared with
72
00:24:42,019 --> 00:24:55,919
e2 and you get c4 and then so what I need
I need a simple comparator .
73
00:24:55,919 --> 00:25:14,799
Now the comparator is defined like this you
have input A you have input B and output is
74
00:25:14,799 --> 00:25:31,220
minimum of a , b and maximum of a, b right
so you need comparator here which takes the
75
00:25:31,220 --> 00:26:13,529
input and gives the output and now if I have
2 elements a and b how man comparators do
76
00:26:13,529 --> 00:26:19,519
you need and if I have a1 ,a2 ,b1 ,b2 these
are the 2 sequences now first problem is that
77
00:26:19,519 --> 00:26:31,000
I want to find out the number of comparators
you need to merge the two sorted sequence
78
00:26:31,000 --> 00:26:34,480
each of size n the number of comparators.
79
00:26:34,480 --> 00:26:42,830
You need to merge 2 sequences my comparator
C 2n is the number of comparators can be written
80
00:26:42,830 --> 00:26:51,019
as C a for this block also again you need
C2n so how many comparators you need n-1 and
81
00:26:51,019 --> 00:29:37,919
you know that your recurrence value is valid
if n=1 if n>1 now if it
82
00:29:37,919 --> 00:30:56,220
is
83
00:30:56,220 --> 00:31:25,490
the case you check whether your recurrence
ready for this one we c1 is 1 2 + 1 so this
84
00:31:25,490 --> 00:32:13,889
is the number of comparators you need we will
solve it later on now the next one is the
85
00:32:13,889 --> 00:32:28,570
number of parallel steps you need to merge
sorted elements.
86
00:32:28,570 --> 00:32:48,419
So T 2n is what tell me
87
00:32:48,419 --> 00:33:40,620
the recurrence relation these two hubs but
they can do in parallel right so I can write
88
00:33:40,620 --> 00:35:16,130
T n+1 if n > 1 if n=1 so I need to know the
solution of this two .
89
00:35:16,130 --> 00:35:39,030
So I can write this one as T n/2 k + 1+ 1
.....+1 how many 1 next time I will write
90
00:35:39,030 --> 00:36:21,080
TN by 2 to the power 2 is equals to 1 + 1
+ 1 still not sure so if
91
00:36:21,080 --> 00:37:16,500
it is K + 1 then it
is k + 2 ,this solution 2 times T n + n - 1
92
00:37:16,500 --> 00:37:55,720
then I can write 2 squares P n by 2 + n - 2
= n - 1 so next time what I will write tell
93
00:37:55,720 --> 00:38:44,550
me what I will write here - cube yet CN by
C n by 4 here n - so
94
00:38:44,550 --> 00:39:16,380
what happens to K times 2 to the power k +
1 C N by 2 to the 4k n - 2 to the power K
95
00:39:16,380 --> 00:40:22,380
so
how many here if + one 0 2 to the power 1
96
00:40:22,380 --> 00:41:56,210
yes so this so you get let us assume that
is 2 F 3 F 4 F 5 is 6 yes basically and you
97
00:41:56,210 --> 00:42:55,490
assume that there are n that is that I have
to find the district group this is another
98
00:42:55,490 --> 00:42:59,350
group.
99
00:42:59,350 --> 00:43:28,370
Two type is C n +n-1okay it is okay C n / 2+n-2+n-1so
next type what I write tell me what I write
100
00:43:28,370 --> 00:43:33,950
here. So 2 cube here C n / 4, n-2+n-1 it is
okay so what happens to K touch K+1, C n/2k,
101
00:43:33,950 --> 00:43:49,010
+ n-1.So how many here. And so on and we assume
(k+1) n+1. So you get C2n= (k+1) n+1, C n=
102
00:43:49,010 --> 00:44:09,370
KN+1 cost is C n x T n here (n log n+1) x
(log n+1). So what is the sequence are you
103
00:44:09,370 --> 00:44:12,710
sure that there are two sequences each of
size 1.
104
00:44:12,710 --> 00:44:25,790
Let us assume that a1, a2, a3, a4, a5, a6,
a7 you assume there are n/2 each and that
105
00:44:25,790 --> 00:44:31,990
has now this is sorted this sequence is sorted
the sequence is sorted this sequence is sorted
106
00:44:31,990 --> 00:44:39,940
this sequence is sorted yes if it is the case
I can have one comparator to give me the sorted
107
00:44:39,940 --> 00:44:53,000
sequence I can have another completed comparator
right. So I get you want me a1 mu a 1 mu a2
108
00:44:53,000 --> 00:45:21,950
mu a3 mu a 4 and so on now you have any elements
these are elements you divide again based
109
00:45:21,950 --> 00:45:27,890
on four elements four elements for another
man this two element sorted these two elements.
110
00:45:27,890 --> 00:45:34,780
Alton you can use ordinary markings for marking
retro to sort this you can use the odd-even
111
00:45:34,780 --> 00:47:01,950
multi-layer network to solve this and so on
yes so that you have consider one example
112
00:47:01,950 --> 00:47:23,940
then you realize this is a numbers you have
113
00:47:23,940 --> 00:49:38,430
so use so you will be getting this sorted
so you can so if you have any limits how many
114
00:49:38,430 --> 00:52:31,080
fingers would be there agree now in the ayat
phase we are looking for in the first phase
115
00:52:31,080 --> 00:52:53,050
you need one component and this is one component
one comparator one compared to water there
116
00:52:53,050 --> 00:53:07,120
are n / 2 parts.
In right now you know I
117
00:53:07,120 --> 00:53:36,580
need to find out I need to find out what happens
for the is space can you tell me in the eye
118
00:53:36,580 --> 00:53:54,570
each face how many parts up there number of
parts diet face in the hospice how many parts
119
00:53:54,570 --> 00:54:26,680
in the second phase in I eat fish and up on
to the power i right and now and in a particular
120
00:54:26,680 --> 00:54:32,290
part shake a paw or a fusspot because they
had symmetrically distributed if you have
121
00:54:32,290 --> 00:54:38,910
trillion here also you have three so I need
to find out any one part how many competitors
122
00:54:38,910 --> 00:54:57,520
in the is and in the in each part how many
elements are there in each part in each part
123
00:54:57,520 --> 00:55:00,110
how many components elements are there number
of elements.
124
00:55:00,110 --> 00:55:14,090
So we will get this solve so you can think
that is taking 1, place 2, so this is place
125
00:55:14,090 --> 00:55:38,380
3right. Now if you any elements how you face
that. Agreed fine the I th phase we are looking
126
00:55:38,380 --> 00:55:43,350
the first place.
127
00:55:43,350 --> 00:55:50,120
You need one cooperator and n/2 parts. This
is 1/cooperator, 1 cooperator, to wards. Then
128
00:55:50,120 --> 00:56:09,790
log and phase you need n log +1 1 right. Now
I need to find out ith phase similarly the
129
00:56:09,790 --> 00:56:30,730
height how many parts are there. Number of
phase in the phase how many phase in the second
130
00:56:30,730 --> 00:57:06,600
phase the height phase write off in the highest
phase and in a particular part first one each
131
00:57:06,600 --> 00:57:18,120
part how many elements are there.
132
00:57:18,120 --> 00:57:41,250
In each part how many cooperate elements are
here number of element very good if I know
133
00:57:41,250 --> 00:58:48,000
students are write I what is the number of
cooperatives we need so the number of elders
134
00:58:48,000 --> 00:59:40,620
Ci is = (2i I +1) yes. So this part you need
total number of total number of complimented
135
00:59:40,620 --> 00:59:59,320
ith phase 1 so I get this want I need ith
phase. So the total number of complimented
136
00:59:59,320 --> 01:00:15,720
= to Ni n/2i right. What is the sub = n log
n (log n+1)/2, + n [1/2+1/2i+1/log n 2] how
137
01:00:15,720 --> 01:00:30,870
do you get in a higher step in the first step
first phase # of steps =1.
138
01:00:30,870 --> 01:00:49,950
Log th phase # of step = log in +1, # step
=log I +1. I get phase number of parallel
139
01:00:49,950 --> 01:01:07,800
steps is log I + 1 yes so the total number
of steps is equal to summation over I equals
140
01:01:07,800 --> 01:02:48,990
to 1 to log in log I + 1 which is log n log
n + 1 so the also sub-problem subject but
141
01:02:48,990 --> 01:03:48,060
here it is a uniform structure comparative
or informal nature and it is a team diagram.
142
01:03:48,060 --> 01:04:22,780
But the # of comparator is see why line here
you observed this party is not being used
143
01:04:22,780 --> 01:04:31,200
when the data has been moved to this phase
this comparator idea.
144
01:04:31,200 --> 01:04:40,490
Now what my point is that came you can you
through some manipulation or some switching
145
01:04:40,490 --> 01:04:51,810
technique so that this can be used for this
also you know only thing is that we see the
146
01:04:51,810 --> 01:04:57,470
structure this structure the structures say
the structure and this structure is same I
147
01:04:57,470 --> 01:05:22,400
could have only this linkage to be changed
right so
148
01:05:22,400 --> 01:05:31,730
that complexity of the connection right by
using say Gino the connection structure is
149
01:05:31,730 --> 01:05:37,410
this the data would be coming from this side.
And if it is one the data will be coming from
150
01:05:37,410 --> 01:06:08,460
this first phase there is simple a converted
a only okay. So you can considered to this
151
01:06:08,460 --> 01:07:15,800
a log then can you use less number of operator
so have this because you can defend and you
152
01:07:15,800 --> 01:07:57,930
can use one of them to find the process. It
is one so design it is okay still thinking
153
01:07:57,930 --> 01:09:10,100
about that one is happy now if it is okay
please so you can define you and you can get
154
01:09:10,100 --> 01:09:15,690
relax.