JuliaCollections/DataStructures.jl

BinaryHeap constructor performs differently from heapify

開放

#639 建立於 2020年6月29日

 (3 則留言) (2 個反應) (0 位負責人)Julia (261 個分叉)batch import
enhancementgood first issue

倉庫指標

星標
 (745 顆星)
PR 合併指標
 (平均合併 1天 18小時) (30 天內合併 3 個 PR)

描述

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.

貢獻者指南