I need a recommendation for a good implementation of merge sort in Java.
Basically, I can write all the merges but if I would have a good jar from a provider such as Apache or Google it would be nicer.
Requirements for the merge sort:
- I get an unknown number of sorted arrays.
- Very important: I get a number that says when to stop (lets say it says 34 on a random incident – I want my algorithm to stop sorting when it reaches that number).
No need to write the code here, I’m only looking for an available jar/library.
I don’t know of a ready-made solution, but it appears simple enough to implement with the help of a priority queue:
Test code:
The space complexity is O(L), and the time complexity is O((L + K) log(L)) where L is the number of lists, and K the number of retrieved elements.