我知道插值搜索是对二进制搜索的一种改进,在二进制搜索中,通过计算,输入在每次迭代中被分成两等份。
mid = (low + high) / 2在插值搜索中,中间值被计算为
mid = low + (key - arr[low]) * ((high - low) / (arr[high] - arr[low]))现在我需要理解在插值搜索中计算mid的公式。
参考文献:实现
发布于 2017-07-16 17:17:17
扩展到@ answer -另一个有趣的答案
他提出的方程是基于插值公式 (一条线的方程)。

现在,将f()视为接受索引并返回其y轴值的函数,
y1 = f(low)
y2 = f(high)
x1 = low
x2 = high
(y - f(low)) = [(f(high) - f(low)) / (high - low)] * (x - low);
OR
x = low + [(high - low) * (y - f(low))] / (f(high) - f(low))
here: y = key
we are looking for position(value) of x.https://stackoverflow.com/questions/32330185
复制相似问题