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

Chapter 13: Constant Time Lookup of Next Node #85

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

christopher-besch
Copy link

@christopher-besch christopher-besch commented Aug 10, 2021

Isn't the lookup time of the next node constant instead of logarithmic?
Current version:

Using a priority queue, the next node to be processed can be retrieved in logarithmic time.

Referring to cppreference.com:

A priority queue [...] provides constant time lookup of the largest (by default) element, at the expense of logarithmic insertion and extraction.

Referring to Page 43:

A priority queue maintains a set of elements [...] and retrieval takes O(1) time.

Referring to cppreference.com:
> A priority queue [...] provides *constant time lookup* of the largest (by default) element, at the expense of logarithmic insertion and extraction.
Referring to Page 43:
> A priority queue maintains a set of elements [...] and retrieval takes O(1) time.
@apronchenkov
Copy link

I think it depends on the interpretation of "retrieved" -- if it includes taking out the node from the queue, it's logarithmic time for heap.

Maybe the fix should be in the chapter 4, something like: "Insertion and removal take O(logn) time,
and finding the maximum takes O(1) time.

@christopher-besch
Copy link
Author

That makes sense; thanks for clearing that up for me.

I've implemented the suggested changes and replaced retrieve with lookup. What do you say?

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.

2 participants