在给定范围内找到前身的数据结构

发布于 2025-01-29 20:14:06 字数 343 浏览 2 评论 0原文

给出了键的列表,说[2、6、4、9、3],我如何找到一个元素的前身,只剩下元素的索引?例如,

  1. 6的前身应该是2,而不是4,因为4在6的右边。4
  2. 的前身应为2,而不是3。

我们知道,在平衡的二进制搜索树中,我们可以找到前身和继任者给定O(log n)时间复杂性中的键,但这并不是我想要的。

我似乎想要一个数据结构,并具有来自BST和间隔树的功能。 但是我不知道如何结合它们。

Given a list of keys, says [2, 6, 4, 9, 3], how can I find the predecessor of an element, with index left to the element only? For example

  1. The predecessor of 6 should be 2, not 4, because 4 is on the right of 6.
  2. The predecessor of 4 should be 2, not 3.

We know that in a balanced binary search tree, we can find predecessor and successor for given key in O(log n) time complexity, but that is not exactly what I wanted.

I seems like I wanted a data structure with functions from both BST and Interval Tree.
But I don't know how to combine them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文