I have a priority queue max heap where each element is a class called Task, which looks as follows (implemented in Java, but question is language-agnostic):
class Task{
int ID
int Priority
int Time
public Task(int i, int p, int t){
this.ID = i;
this.Priority = p;
this.Time = t;
}
//Getters, etc
}
The heap is obviously sorted by priority. The operation I want to perform is to find the highest priority item, decrement its Time value, and remove it from the heap if the time score changes to 0. HOWEVER, here's the catch: there is allowed to be more than one Task with the same Priority. In this case, I compare the ID scores of all such Tasks and operate on the lowest one.
What would be the worst case running time of such an operation? If every element has the same Priority, I would end up searching through the entire tree, meaning that this couldn't possibly be done in less than O(n) time, correct? This seems impossible to get around because the IDs are unsorted. However, I'm told that this is possible to do in O(log n), which I don't understand at all. Would anyone be able to clarify where I'm approaching this wrong?