A
arnuld
Insert is surely Log N for an ordered array? Mind you, I am not sure
what is being measured here, so who knows. Maybe data moves are being
measured and some technique is used to reduce moves on delete. I don't
know.
If by Ordered array he means that, all elements are inserted with
ascending or descending order of priority, then of course it will take N,
because you have to do N comparisons to find the proper place to insert.
It does. I don't see a problem. I'd use an array-based heap with a
clean interface so I could change it later if the large block
allocations became a problem (I am told they can be in embedded
systems). In fact, I'd probably use a sorted linked list or an ordered
array to prototype the code and plug in a heap later if inserts were
getting too slow. I am very fond of rapid prototyping.
I am writing a queue implementation of doubly linked list where elements
are added in descending order of priority. That way delete max will
always be 1 but insertion will be N in worst case.
or you think I should use a general queue, adding anywhere and then
insert will be 1 but delete max will be N ?