Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

spirited_away_'s blog

By spirited_away_, history, 7 years ago, In English

I want to delete some element in a priority queue not at the top, how should i do? can someone suggest any method, in constant or logarithmic time. How to handle duplicates while removing

| Write comment?
»
7 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

It's not possible. In a heap(or pq) finding an element in itself is linear.

»
5 years ago, hide # |
 
Vote: I like it -13 Vote: I do not like it

Is it possible to delete any random elements from multiset ,suppose multiset contains 10 elements , so is it possible to delete, say 5th element?

»
5 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

use multiset instead

»
4 years ago, hide # |
 
Vote: I like it +66 Vote: I do not like it

You can remove the top easily.

If you want to delete another element, you can do it "lazily": when you are given an element to delete from the priority_queue, store somewhere else that this element no longer belongs there (for examplein a map or in a vector of booleans). Then, when you have a "top" request on the priority queue, pop until you reach an element actually still in the queue, according to the other data structure.