Mergesort is a sorting technique also works on divide and conquer
technique as in quicksort technique. In this video I discuss with you
the working of this merge sort with help of an example. The first
step is dividing the given list into sub lists and the second step is
merging of those sub lists. C merge sort is a function merge suit is
array we are going to pass lower bound and upper bound this is
lower bound. If two elements are there then then you're going to
divide that particular list into sub lists. Then each each sub list is
having only one element and that is the condition you have to stop
dividing you will keep on dividing the sub list. The main thing is you
have to write down the code for this merge function that this
backbone of the merge function how we are going to merge these
arrays. The code is a recursion call to left part n to right part so this
is a call to a recursively call.
Midpoint is midpoint fine so here we call merge sort 0 - middle
element is 0 because 0 plus 1 that is 1 1 divided by 2 is 0 and then
again merge sort 1 to 1 and again we are going to call merge
methadone 0 metal point is lower bound is 0. This is the recursive
tree now how this is going to be called see first of all massive of 0 to
8 here we have first cold would we do this function 0 to 4 again for
first sorting of this one. We are going to call merge 5 then 5 and
then 6 fine lower bound is 5 mid is also 5 and upper bound is six
now seven 8 7 is less than this it yes this condition is true. We are
going to merge these list with its adjacent lest only and when you're
going to draw this recursion tree then you come to know that how
we are. merging these sub lists will be merged this and this that is
why I am saying you can not merge this 15 with 8 or 15 with 24 but
it 's not like that if this 5 and 15 is 1 list and you are merging this
with 8 no.
I am going to discuss with you how this merge function is going to
be executed. We are going to compare the first element of these
sub lists fifteen and five which one is less five is less. then here six
to six then merging would be done then again back to seven to
eight then this one this one and then finally merging of these lists
fine. Time complexity for this merging function would be what theta
M plus in M is number of elements in one sorted sub list and is
number in another sorted sub lists. When you are going to add these
elements into this one then how many elements would be there in
this key in this sub list M plus n. If you write down the code for this
technique as in quicksort technique. In this video I discuss with you
the working of this merge sort with help of an example. The first
step is dividing the given list into sub lists and the second step is
merging of those sub lists. C merge sort is a function merge suit is
array we are going to pass lower bound and upper bound this is
lower bound. If two elements are there then then you're going to
divide that particular list into sub lists. Then each each sub list is
having only one element and that is the condition you have to stop
dividing you will keep on dividing the sub list. The main thing is you
have to write down the code for this merge function that this
backbone of the merge function how we are going to merge these
arrays. The code is a recursion call to left part n to right part so this
is a call to a recursively call.
Midpoint is midpoint fine so here we call merge sort 0 - middle
element is 0 because 0 plus 1 that is 1 1 divided by 2 is 0 and then
again merge sort 1 to 1 and again we are going to call merge
methadone 0 metal point is lower bound is 0. This is the recursive
tree now how this is going to be called see first of all massive of 0 to
8 here we have first cold would we do this function 0 to 4 again for
first sorting of this one. We are going to call merge 5 then 5 and
then 6 fine lower bound is 5 mid is also 5 and upper bound is six
now seven 8 7 is less than this it yes this condition is true. We are
going to merge these list with its adjacent lest only and when you're
going to draw this recursion tree then you come to know that how
we are. merging these sub lists will be merged this and this that is
why I am saying you can not merge this 15 with 8 or 15 with 24 but
it 's not like that if this 5 and 15 is 1 list and you are merging this
with 8 no.
I am going to discuss with you how this merge function is going to
be executed. We are going to compare the first element of these
sub lists fifteen and five which one is less five is less. then here six
to six then merging would be done then again back to seven to
eight then this one this one and then finally merging of these lists
fine. Time complexity for this merging function would be what theta
M plus in M is number of elements in one sorted sub list and is
number in another sorted sub lists. When you are going to add these
elements into this one then how many elements would be there in
this key in this sub list M plus n. If you write down the code for this