简体   繁体   English

java.util.TreeSet的tailSet操作的时间复杂度是多少?

[英]What is the time complexity of the tailSet operation of java.util.TreeSet?

I was implementing the 2D closest pair algorithm using sweepline, and it says that you need to find the six points above a certain y coordinate. 我正在使用扫掠线实现2D最接近对算法,它说您需要找到某个y坐标上方的六个点。 What I did is I put the points in a TreeSet sorted by y-coordinate, and used the tailSet method to get all points above a certain point, and iterate up to 6 times. 我所做的是将这些点放入按y坐标排序的TreeSet中,并使用tailSet方法获取高于某个点的所有点,并进行最多6次迭代。

I was wondering if the complexity of the tailSet operation is O(log n), and if it is, is iterating over the tailSet at most six times also O(log n)? 我想知道tailSet操作的复杂度是否为O(log n),如果是,是否在tailSet上最多重复六次O(log n)?

Reference: http://people.scs.carleton.ca/~michiel/lecturenotes/ALGGEOM/sweepclosestpair.pdf 参考: http : //people.scs.carleton.ca/~michiel/lecturenotes/ALGGEOM/sweepclosestpair.pdf

AFAIK将tailSet设为O(log n),但对最后m元素进行迭代则为O(m * log n)

Hmm... It's strange to me. 嗯...对我来说很奇怪。 I thought that in terms of big O a process of creating a tailSet inside java.util.TreeSet is O(1). 我认为就大O而言,在java.util.TreeSet内部创建tailSet的过程是O(1)。

Small clarification: tailSet(), headSet() and subSet() return very small objects that delegate all the hard work to methods of the underlying set. 简要说明:tailSet(),headSet()和subSet()返回非常小的对象,这些对象将所有艰苦的工作委托给基础集合的方法。 No new set is constructed. 没有构建新的集合。 Hence O(1) and pretty insignificant. 因此,O(1)并无关紧要。

a link for discussion 讨论链接

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

相关问题 hack:在java.util.TreeSet中重复吗? - Hack: Duplicates in java.util.TreeSet? GSON:使用java.util.TreeSet序列化对象 - GSON: Serialize object with java.util.TreeSet java.util.HashSet和java.util.TreeSet使用什么算法在其结构中存储唯一值? - What Algorithm is used by java.util.HashSet and java.util.TreeSet to store unique values in its structure? 是什么原因导致ClassCastException:java.util.TreeSet无法转换为java.lang.Comparable? - What causes the ClassCastException: java.util.TreeSet cannot be cast to java.lang.Comparable? Java中TreeSet的lower()/ higher()的时间复杂度是多少? - What is the time complexity of lower()/higher() of TreeSet in Java? 自定义包装的枚举类型不支持java.util.TreeSet集合类型 - java.util.TreeSet collection type not supported for custom wrapped enum type TreeSet迭代的时间复杂度是多少? - What is the time complexity of TreeSet iteration? 在Java中使用Set / TreeSet的平均时间复杂度是多少? - what is the average time complexity of using Set/TreeSet in java? Java类TreeSet中的Java方法headSet和tailSet是否在log(N)时间内工作? - Do Java methods headSet and tailSet in Java class TreeSet work in log(N) time? TreeSet中有序操作的时间复杂度是多少? - What is the time complexity of ordered operations in TreeSet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM