JuliaCollections/DataStructures.jl

BinaryHeap constructor performs differently from heapify

Offen

#639 geöffnet am 29.06.2020

 (3 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)Julia (261 Forks)batch import
enhancementgood first issue

Repository-Metriken

Stars
 (745 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 18h) (3 gemergte PRs in 30 T)

Beschreibung

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.

Contributor Guide