JuliaCollections/DataStructures.jl

BinaryHeap constructor performs differently from heapify

Ouverte

#639 ouverte le 29 juin 2020

 (3 commentaires) (2 réactions) (0 personne assignée)Julia (261 forks)batch import
enhancementgood first issue

Métriques du dépôt

Stars
 (745 étoiles)
Métriques de merge PR
 (Merge moyen 1j 18h) (3 PRs mergées en 30 j)

Description

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.

Guide contributeur