From the PriorityQueue Javadoc:
Implementation note: this implementation provides O(log(n)) time for enqueuing and dequeuing methods
offer,poll,remove()andadd; linear time for theremove(Object)andcontains(Object)methods; and constant time for the retrieval methodspeek,element, andsize.
So, my question is, would the O(log(n)) time complexity hold up for merging PriorityQueues into one? Or would it be O(nlog(n)) considering the insertion? And would this change if merging more heaps?
These PriorityQueues are to represent heaps.
Something like this:
PriortityQueue<Integer> a = new PriorityQueue<>();
... add elements
PriortityQueue<Integer> b = new PriorityQueue<>();
... add elements
PriorityQueue<Integer> merged = new PriorityQueue<>(a.size() + b.size(), a.comparator()); // Assuming a and b have the same Comparator.
merged.addAll(a);
merged.addAll(b);