When we have two binary min heaps implemented as doubly sorted linked links , what's the most efficient algorithm regarding the worst-case time to merge one heap into another ,
What I though myself, is that I would insert the elements of the heap with smaller number of elements in to the heap with larger number of elements :
If I have random access to elements (Which is usually not the case with linked list) it would be done in O(m * log(n+m))
where m < n
because I can insert each element of smaller heap into the larger heap, otherwise it would be O(m * n)
because I have to insert each element in to the least of already sorted list.
Is there any other idea that works faster and have better worst time ?