473,703 Members | 3,137 Online

# What's the difference between the priority queue & set & heap ?

i need some explanation about the difference between priority queue &
set & heap ... as they all sort the data in ( n log n ) ... but the
only i see that priority queue only can pop the top ( maximum
element ) while set and heap can erase any element ...

Aug 8 '07 #1
3 7427
On Aug 8, 12:44 pm, PicO <bekerp...@gmai l.comwrote:
i need some explanation about the difference between priority queue &
set & heap ... as they all sort the data in ( n log n ) ... but the
only i see that priority queue only can pop the top ( maximum
element ) while set and heap can erase any element ...
i also read that .. i can make a heap from priority queue ....
how ? ...

Aug 8 '07 #2
PicO wrote:
i need some explanation about the difference between priority queue &
set & heap ... as they all sort the data in ( n log n ) ... but the
only i see that priority queue only can pop the top ( maximum
element ) while set and heap can erase any element ...
The advantage of a priority queue (in cases where you just need the
smallest item in a group of values) over a set is that the priority
queue will take much less memory. A priority queue can be constructed
into a vector (ie. a contiguous array) and thus it will only require
as much memory as the sizes of the elements. A set will take much more
memory (because besides the elements themselves it needs 3 pointers
per element, plus the additional overhead caused by allocating each
element dynamically).
Aug 9 '07 #3
On Aug 9, 3:18 am, Juha Nieminen <nos...@thanks. invalidwrote:
PicO wrote:
i need some explanation about the difference between priority queue &
set & heap ... as they all sort the data in ( n log n ) ... but the
only i see that priority queue only can pop the top ( maximum
element ) while set and heap can erase any element ...

The advantage of a priority queue (in cases where you just need the
smallest item in a group of values) over a set is that the priority
queue will take much less memory. A priority queue can be constructed
into a vector (ie. a contiguous array) and thus it will only require
as much memory as the sizes of the elements. A set will take much more
memory (because besides the elements themselves it needs 3 pointers
per element, plus the additional overhead caused by allocating each
element dynamically).
thanks juha .. that's i want the smallest one so I'll use priority
queue ...

Aug 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.