4. temp to original array
for k=low to high
a[k]=b[k]
}
If(h>mid)
{
for k=j to high
{
b[i]=a[k]
i=i+1
}
}
else
{
for k=h to mid
{
b[i]=a[k]
i=i+1
}
}
5. Recursion Order
8 3 2 9 7 1 5 4
8 3 2 9 7 1 5 4
8 3 2 9 7 1 5 4
8 3 2 9 7 1 5 4
3 8 4 51 72 9
2 3 8 9 1 4 5 7
1 2 3 4 5 7 8 9
1
2
3 4
5
6
7 8
9
10
11
12
13 14
15
16
17 18
19
20
21
Note :The numbers in red help to understand the order in which recursion takes place
6. Formulating the Recurrence Relation
T(n)=2T(n/2)+(n-1)
Size of a sublist
Number of sublists
(n-1)
Number of times basic operation is performed when a function is called
Inside Merge() a minimum of (n-1) comparisons is performed.
Eg.
If 1 element no comparison
If 2 elements->max 1 comparison
If 4 elements->3 comparisons