Priority queues and heaps

Hi

In priority queue you insert items with key and value.  The priority is going to be "performed" on the keys.  So if you have some keys and some values where the keys are inserted (does not matter in which order) as keys = {1, 6, 32, 1} then the order in which you will get items out (note not just the keys also the attached values0 would be: 1, 1, 6, 32.

Note you can have duplicates.

Note that we first take items from min to max, its not a must we can also sort the priority queue from max to min.

to get the min value its gong to take Teta(1)  because you just look at it.
The most common data structure to hold it is an array, then you can say the childs of any nodes are in 2n, 2n+ 1 cells in the array.

Comments