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.

贡献者指南