DataStructures.jl icon indicating copy to clipboard operation
DataStructures.jl copied to clipboard

BinaryHeap constructor performs differently from heapify

Open Indigo2233 opened this issue 4 years ago • 3 comments

I noticed that BinaryHeap like BinaryMinHeap constructs a heap that just insert every element from an array to a empty heap. And the following x and y have the same order:

julia> nums = rand(1:20000, 2000);

julia> x = MutableBinaryMinHeap(nums);

julia> y = BinaryMinHeap(Int.([]));

julia> for i in nums 
           push!(y, i)
       end

However, there is an O(N) heap-building algorithm instead of O(NlogN), and function heapify is an implement. So why not use heapify instead of insert successively?

Sincerely.

Indigo2233 avatar Jun 29 '20 01:06 Indigo2233

Hi @oxinabox @AquaIndigo I am interested in fixing this, but I am relatively new to Julia. Any tips on getting started? Thanks!

AliMalik9599 avatar Aug 11 '20 10:08 AliMalik9599

I recommend asking on julialang slack or Discourse. The code change should be fairly straight forward if you are familar with the constructor in question and the heapify function

oxinabox avatar Aug 11 '20 13:08 oxinabox

@AliMalik9599 Are you still working on this issue?

zerefwayne avatar Oct 23 '20 16:10 zerefwayne