Skip to content

Construct MutableBinaryHeap in O(N) using bottom-up bubble down (fixe… - #1003

Open
dhrubchatterjee16-lang wants to merge 1 commit into
JuliaCollections:masterfrom
dhrubchatterjee16-lang:linear-mutable-heap-build
Open

dhrubchatterjee16-lang wants to merge 1 commit into
JuliaCollections:masterfrom
dhrubchatterjee16-lang:linear-mutable-heap-build

Conversation

@dhrubchatterjee16-lang

Copy link
Copy Markdown

Summary

Resolves #639 by changing MutableBinaryHeap array-based construction from successive O(N log N) insertions to Floyd's O(N) bottom-up heap building algorithm.

Changes

  • src/heaps/mutable_binary_heap.jl:
    • Replaced the 1:n loop of _heap_bubble_up! in _make_mutable_binary_heap with (n >> 1):-1:1 calling _heap_bubble_down!.
    • Drops heap construction time complexity from O(N log N) to linear O(N) while preserving handle mappings in nodemap.
  • test/test_mutable_binheap.jl:
    • Updated expected heap_values for MutableBinaryMaxHeap to match the bottom-up heapify layout.
    • Added @test verify_heap(h) checks across constructors.
    • Added parameterized test cases across multiple array sizes verifying min/max heap validity and handle preservation.

Fixes #639

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BinaryHeap constructor performs differently from heapify

1 participant