You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
- Does the standard guarantee that make_heap will be cheap (logarithmic) in this special case? I also would like to avoid using a deque, I prefer vector for speed. (size of q will not increase over time). I would like to just put the new element at the front of the vector, and then sift it down until I have re-established the min-heap property. Maybe best to roll my own.Erik Alapää– Erik Alapää2017-02-09 16:37:52 +00:00Commented Feb 9, 2017 at 16:37
- If I am remembering correctly, make_heap is the same algorithm that is used in priority queue. So, if you intend to use priority queue, there is no reason to avoid using make_heap.Zeta– Zeta2017-02-09 16:45:00 +00:00Commented Feb 9, 2017 at 16:45
- But for a std::priority_queue, you often just call make_heap once at the beginning (expensive), then just pop and push elements often (push and pop are logarithmic).Erik Alapää– Erik Alapää2017-02-09 16:47:47 +00:00Commented Feb 9, 2017 at 16:47
- I wanted to say that the cost of using pri queue is more than using make_heap.Zeta– Zeta2017-02-09 16:58:56 +00:00Commented Feb 9, 2017 at 16:58
- Why? std pri q is just an adapter/wrapper over make_heap, push_heap and pop_heap. And the algorithmic complexity is as it should be in a heap.Erik Alapää– Erik Alapää2017-02-09 17:12:55 +00:00Commented Feb 9, 2017 at 17:12
| Show 3 more comments
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. python-3.x), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-cpp