Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the latest version of make_heap run in O(n) #1

Open
Morwenn opened this issue Feb 5, 2018 · 2 comments
Open

Does the latest version of make_heap run in O(n) #1

Morwenn opened this issue Feb 5, 2018 · 2 comments
Labels

Comments

@Morwenn
Copy link
Owner

Morwenn commented Feb 5, 2018

I am pretty bad a complexity analysis, but reading again how a make_heap function runs in O(n) time and not in O(n log n) time makes me thing that the poplar::make_heap implementation based on binary carry sequence actually runs in O(n):

  • When an element corresponds to the root of a single-element poplar, sift is never called. Those elements constitute half of the heap.
  • When an element corresponds to the root of a three-element poplar, sift is called but can't go deeper than one level. Those elements constitute a quarter of the heap.
  • For roots of bigger poplars, the number of such elements in always halved while the maximum depth of sift increases.

I'm not able to perform a proper complxity analysis, but it looks awfully close to what makes std::make_heap run in O(n), so I'm wondering whether the same analysis applies to poplar::make_heap and whether it actually runs in O(n).

The version based on push_heap can't run in O(n) because we always need to compute the size of the last poplar in O(log n) time, but the version based on the binary carry sequence computes the size of the poplar in which an element needs to be sifted in O(1), so it might actually run in O(n) if the complexity analysis of a regular make_heap method applies.

@firejox
Copy link

firejox commented Jun 2, 2019

The poplar heap is quite similar to the post-order heap. Hence, I think it could possibly run in O(n) time.

@Morwenn
Copy link
Owner Author

Morwenn commented Jun 3, 2019

It does seem to describe the same data structure albeit with a different name (I'm surprised I never found this paper before) even though the tricks used to compute the element positions seem to differ. I'll read it more in detail when I have time, thanks for the link :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants