[英]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)并无关紧要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.