Odd-Even Merge Sort Base Case?
Closed this issue · 2 comments
HaritzPuerto commented
Hello,
I think we need a base case in the code. I mean something like this:
`
procedure Merge(A,B)
if len(A) == len(B) == 1 then
return <min(A[0], B[0]), max(A[0], B[0])>
else then
(A_o, A_e) = ....
`
If we do not have this base case at the beginning, we would have an infinite recursion, wouldn't we? If A and B are composed of just one element, A_o = A and A_e = <> (Indexes start at 1). The same with B. So, Merge (A_o, B_o) would be the same as the original call Merge(A, B)
Am I right or am I missing something?
Thank you
jeehoonkang commented
You're right. We indeed need a base case. Thank you for pointing out that!
HaritzPuerto commented
Thank you!!