From the javadoc for the
java.util.PriorityQueue class:
- "Implementation note: this implementation provides O(log(n))
time for the enqueing (adding) and dequeing (removing) methods"
Recall the difference between
O(n) (linear) and
O(log(n))
(logarithmic) time:
n | log(n)
|
8 | 3
|
16 | 4
|
32 | 5
|
... | ...
|
512 | 9
|
1024 | 10
|
How does java.util.PriorityQueue achieve logarithmic time performance?