Two Priority Queue

I have a data set and I want to find the largest and smallest objects (several times), what is the best way to do this?

For everyone who is interested in the application, I am developing a level of detail for the system, and I need to find the elements with the largest and smallest screen errors, obviously every time I split / merge the element that I have to insert into the queue, but every time the camera moves all changes to the data set, so it’s best to use a sorted list and defer adding new items until the next sort (since this happens so often)

+6
c # data-structures
source share
1 answer

You can use the Min-Max Heap as described in the Min-Max Heaps and Generic Priority Queues article:

Simple implementation of double priority queues introduced. The proposed structure, called the min-max heap, can be embedded in linear time; unlike regular heaps, this allows FindMin and FindMax to be executed at a constant time; Insert, DeleteMin, and DeleteMax operations can be performed in logarithmic time.

+5
source share

All Articles