Java: is there a way to construct a max-heap from an array in O(n) using PriorityQueue? -


correct me if i'm wrong, think priorityqueue(collection c) constructor create min-heap collection in time o(n). however, couldn't find constructor can pass both collection , comparator (in order convert min-heap max-heap). wondering if there way construct max-heap array (say, int array) in o(n) using priorityqueue?

no, having set of elements arranged in min-heap not provide advantage rearranging them max-heap. also, seem assuming priorityqueue constructors accept collection have o(n) asymptotic complexity. that's plausible -- -- not documented, not safe rely on it.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -