Hi guys, I have made code of merge sort like this(int terms of algorithm):
Merge_Sort(A, p , r)
{
if (p<r)
q= Lower.Bound( (q+r)/2 ) // for example if 2.5 => q=2 etc ..
Merge_Sort(A, p, q);
Merge_Sort(A, q+1, r);
Merge(A, p, q,r );
}
that's fine .. but my question the prof said it doesn't matter if you use Lower.Bound or Upper.Bound for the median .. but if I use Upper.Bound (meaning if 2.5 => 3) as we will get infinite loop of recursive call (try Merge_Sort(A, 4,5) ) and that's incorrect ! anyone can help me how the prof claim that's upper or lower bound doesn't matter? thanks
Merge_Sort(A, p , r)
{
if (p<r)
q= Lower.Bound( (q+r)/2 ) // for example if 2.5 => q=2 etc ..
Merge_Sort(A, p, q);
Merge_Sort(A, q+1, r);
Merge(A, p, q,r );
}
that's fine .. but my question the prof said it doesn't matter if you use Lower.Bound or Upper.Bound for the median .. but if I use Upper.Bound (meaning if 2.5 => 3) as we will get infinite loop of recursive call (try Merge_Sort(A, 4,5) ) and that's incorrect ! anyone can help me how the prof claim that's upper or lower bound doesn't matter? thanks