Algorithms and Data Structures · Senior · Question 20 of 75

How do you merge k sorted lists with n elements in total efficiently?

Explanation

Each step pops the smallest head and pushes the next element from the same list. Merging one by one is O(n × k) in the worst case; concatenating and sorting is O(n log n).

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 20

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz