I was reading the solutions here: https://leetcode.com/problems/merge-k-sorted-lists/solution/ on how to union k sorted linked lists into one linked list.
A trivial solution would be to write a function that does the job for 2 linked lists, call it on first 2 lists then call it again with the previous result and the 3rd linked list then again with previous result and 4th linked list and so on.
Another more efficient solution is to do the following:
Pair up k lists and merge each pair.
After the first pairing, k lists are merged into k/2 lists with average 2N/k length, then k/4, k/8 and so on.
Repeat this procedure until we get the final sorted linked list.
My question is: Why the second is more efficient, my mind refuses to accept this fact since I think that we are doing same job in different order. where that improvement came from? what facts did we use to make it faster?
I clarified my question in last comment.