Java PriorityQueue(堆)插入n个元素的时间复杂度?

编程入门 行业动态 更新时间:2024-10-28 00:22:29
本文介绍了Java PriorityQueue(堆)插入n个元素的时间复杂度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道Java PriorityQueue.Add()对于n元素的时间复杂度是多少.

I would like to know what the time complexity of Java PriorityQueue.Add() is for n elements.

我知道插入单个元素可能会导致更坏的情况,但是我不清楚插入n个元素的集合的时间复杂度是多少?

I understand that potential worse case insertion a single element is O(log(n)), but it is not clear to me what the time complexity is for inserting a collection of n elements?

我已经从各种来源(没有证据)中断言,建立n元素的优先级队列堆的时间是O(n),并且还看到了断言是O(nlog(n))的时间,这使得感觉到给定的插入是O(log(n)),乘以n倍实际上等于O(nlog(n))

I've seen claims from various sources (with no proofs) that the time to build a priority queue heap of n elements it is O(n), and have also seen claims that it is O(nlog(n)), which makes sense given insertion is O(log(n)), which multiplied n times would indeed equal O(nlog(n))

注意:我只对更坏的情况感兴趣,不会摊销.

Note: I'm only interested in worse case, not amortized.

此问题假定存在一种逻辑方法来描述用n元素填充数据结构(堆)的行为,这与简单地单独考虑n x log(n)插入不同.

This question assumes there is a logical way to describe the act of populating a data structure (heap) with n elements, that is different than simply considering n x log(n) insertions individually.

我对输入没有任何假设(例如输入值集的边界或部分排序的输入).

I'm making no assumptions regarding the input (such as a bounds on the set of input values, or a partially ordered input).

推荐答案

通常情况下为 O(N log N).对于已经订购了输入的特殊情况,存在 O(N)算法,但是java.util.PriorityQueue中未提供此算法.

It is O(N log N) in the general case. An O(N) algorithm exists for the special case where the input is already ordered, but this isn't provided in java.util.PriorityQueue.

更多推荐

Java PriorityQueue(堆)插入n个元素的时间复杂度?

本文发布于:2023-11-29 01:36:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644772.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复杂度   元素   时间   Java   PriorityQueue

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!