By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
On Aug 8, 12:44 pm, PicO <bekerp...@gmail.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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.