6

I'm comparatively new to algorithm analysis and am taking a related course on coursera where I came accross k way merge sort.

The time complexity of 2 way merge sort is n log2 n, of 3 way merge sort is n log3 n and of 4 way merge sort is n log4 n.

But, in the case of k-way the complexity is nk^2. This is because we pay attention to the merge part of the algo; (2n + 3n + 4n...kn).

But, in case of 2, 3 and 4-way algorithms, we pay attention to the recursive call of one function; (2T(n/2) + c.n).

Can anybody please explain why this is so? Or correct my approach to this question.

asked May 15, 2014 at 15:22

2 Answers 2

1

the recursion depth is log n/log k,

merging costs n*log k, using a min heap for log k per element

thus we come at T(n) = n* log k + K* T(n/k) which (unless I'm mistaken) becomes n log n (actually n (c_1/k+log(n))= n/k + n*log(n) but the n/k becomes insignificant in big O)

answered May 15, 2014 at 15:36
0

I'm pretty sure the complexity of k way merge sort is O(knlog_k(n)) not O(nk^2) without implementing other algorithms or data structures. O(kn) per step of the algorithm, and log_k(n) steps. Doubt you still need an answer tho since it has been seven years...

answered Nov 23, 2022 at 17:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.