faqts : Computers : Programming : Languages : Python : Common Problems : Data Structures

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

18 of 29 people (62%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

What is the use of a heap data structure?

May 14th, 2000 05:51
unknown unknown, Courageous


A heap priority queue has the property such that the elements
can be inserted and pulled out in a user-defined order in O(log N)
time. So, for example:

heap.push(7)
heap.push(3)
heap.push(9)
heap.push(2)

would be popped()

as 2,3,7,9

Obviously such a data structure is only needed when appending
onto the end all the time isn't possible (otherwise you'd
just use something like a fifo, both pushing and popping in
O(1)).