Sorted queue with dropping out elements

Posted by ffriend on Stack Overflow See other posts from Stack Overflow or by ffriend
Published on 2012-11-23T17:02:50Z Indexed on 2012/11/23 17:04 UTC
Read the original article Hit count: 176

Filed under:
|

I have a list of jobs and queue of workers waiting for these jobs. All the jobs are the same, but workers are different and sorted by their ability to perform the job. That is, first person can do this job best of all, second does it just a little bit worse and so on. Job is always assigned to the person with the highest skills from those who are free at that moment. When person is assigned a job, he drops out of the queue for some time. But when he is done, he gets back to his position. So, for example, at some moment in time worker queue looks like:

[x, x, .83, x, .7, .63, .55, .54, .48, ...]

where x's stand for missing workers and numbers show skill level of left workers. When there's a new job, it is assigned to 3rd worker as the one with highest skill of available workers. So next moment queue looks like:

[x, x, x, x, .7, .63, .55, .54, .48, ...]

Let's say, that at this moment worker #2 finishes his job and gets back to the list:

[x, .91, x, x, .7, .63, .55, .54, .48, ...]

I hope the process is completely clear now. My question is what algorithm and data structure to use to implement quick search and deletion of worker and insertion back to his position.

For the moment the best approach I can see is to use Fibonacci heap that have amortized O(log n) for deleting minimal element (assigning job and deleting worker from queue) and O(1) for inserting him back, which is pretty good. But is there even better algorithm / data structure that possibly take into account the fact that elements are already sorted and only drop of the queue from time to time?

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about data-structures