mergesort dividing the sequence not into half

안진원 picture 안진원 · Apr 27, 2013 · Viewed 8.3k times · Source

usually, mergesort is performed by dividing the sequence into half and recursively sorting it. however is it also possible to perform mergesort by dividing the sequence by a third?

mergesort(array, start, last) {
tri_mid = (start+last)/3;
mergesort(array, start, tri_mid);
mergesort(array, tri_mid+1, last);
merge(array, start, last);
}

will this work? And if it does, What will the bigO notation be?

Answer

Fred Foo picture Fred Foo · Apr 27, 2013

This should work just fine if you include a third recursive call and write the merge procedure correctly. By the master theorem, the complexity is still O(n log n).