简体   繁体   English

Java PriorityQueue.remove() 时间复杂度? O(log N) 还是 O(N)?

[英]Java PriorityQueue.remove() time complexity? O(log N) or O(N)?

PriorityQueue pq = new PriorityQueue<>(); PriorityQueue pq = new PriorityQueue<>(); Assuming the priorityQueue pq has size N, what is the time complexity for pq.remove()?假设priorityQueue pq 的大小为N,pq.remove() 的时间复杂度是多少?

Is it O(log N) or O(N)?是 O(log N) 还是 O(N)?

From the documentation of PriorityQueue :PriorityQueue的文档中

[...] [...]

Implementation note: this implementation provides O(log(n)) time for the enqueuing and dequeuing methods ( offer , poll , remove() and add );实现说明:此实现为入队和出队方法( offerpollremove()add )提供了 O(log(n)) 时间; linear time for the remove(Object) and contains(Object) methods; remove(Object)contains(Object)方法的线性时间; and constant time for the retrieval methods ( peek , element , and size ).以及检索方法( peekelementsize )的恒定时间。

[...] [...]

One should, however, point out that this is not part of any interface-contract.但是,应该指出这不是任何接口合同的一部分。 Thus, it is an implementation detail.因此,这是一个实现细节。 As such, it could change without prior notice or when using a non-Oracle JDK and should therefore not be relied upon.因此,它可能会更改,恕不另行通知或使用非 Oracle JDK 时,因此不应依赖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM