user1071840
user1071840

Reputation: 3592

Time complexity of storing priority queue as a doubly linked list

If I want to store a priority queue as a sorted doubly-linked list then aren't the following time complexities correct?

Upvotes: 1

Views: 1016

Answers (1)

Skriptkiddie
Skriptkiddie

Reputation: 413

Besides the fact, that a priority queue using linked lists is a somewhat inefficient idea (you can make the worst runtime complexity log(n()), your numbers are right.

You could make a destiction here though: "Insert a new entry: O(n)"

Technically, the insertion is O(1), finding the correct position is what takes you O(n). So basically, when you add 7 identical items, it will not take you 7 times the amount of time, because you need the lookup just once.

Upvotes: 2

Related Questions