爪哇。树集继承者
我对这样一个问题感兴趣:正如我们所知,红黑树提供了后继(该条目更高的第一个元素)和等操作的有效实现前任,即日志时间。 在Java文档中写道,为了提供作为后继的操作,您可以仅使用subSet,然后获取subSet中的最小元素。但这是日志时间吗?如果是的话,subSet的实现是什么?(我对算法很感兴趣,所以可能只是几句话,不是必需的代码)
谢谢。
I am interested in such a question: as we know, Red-Black tree provides efficient implementation of such operations as successor (the first element higher that entry) and predecessor , i.e. in log - time.
In Java documentation is written that for providing such operation as successor you may merely use subSet and then took the least element in the subSet. But is it log-time? If it is, what is the implementation of subSet?(I am interested in the algorithm, so it may be just few words, not necessary code)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是阅读代码来看看它是如何工作的。
我相信 subSet 是 O(log N) 更自然的方法是使用旨在执行此操作的
lower(E)
和higher(E)
方法。http://docs.oracle.com/javase/7 /docs/api/java/util/NavigableSet.html
I would just read the code to see how it works.
I believe subSet is O(log N) A more natural approach would be to use the
lower(E)
andhigher(E)
methods which is designed to do this.http://docs.oracle.com/javase/7/docs/api/java/util/NavigableSet.html