Skip to content

BinaryHeap constructor performs differently from heapify #639

Open
@Indigo2233

Description

@Indigo2233

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions