What is the time complexity of constructing a PriorityQueue from a collection?
问题 What is the complexity of Java's PriorityQueue constructor with a Collection ? I used the constructor: PriorityQueue(Collection<? extends E> c) Is the complexity O(n) or O(n*log(n))? 回答1: The time complexity to initialize a PriorityQueue from a collection, even an unsorted one, is O(n). Internally this uses a procedure called siftDown() to "heapify" an array in-place. (This is also called pushdown in the literature.) This is counterintuitive. It seems like inserting an element into a heap is