algorithm - 在已排序的数组中查找已移位的元素

标签 algorithm

Possible Duplicate:
Searching a number in a rotated sorted Array

假设原始列表是 1 2 3 4 5 6 7 8 9 10

然后你将其移动,使其变为

5 6 7 8 9 10 1 2 3 4

所以说我想检查 7 是否在数组中。我如何有效地做到这一点。

最佳答案

使用三元搜索。它的工作原理与二分查找类似(也是对数时间),但是当序列形状像楔形 (/) 或 V 形 (/) 时,您可以找到元素。

关于algorithm - 在已排序的数组中查找已移位的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2961679/

相关文章:

algorithm - 复制算法并感到内疚

算法回答 'possibility of building a triangle' 查询

algorithm - 队列中的前 n 个元素

c# - 具有独特元素和快速添加和删除的数据结构

c# - 复杂线条背后的逻辑

java - 证明递归算法的时间复杂度

c++ - 算法分析 : Am I analyzing these algorithms correctly? 如何解决这些问题

algorithm - 如何用不相交的线连接两种类型的点?

c# - 合并树节点

PHP 函数 'return' 没有返回值