线性插值插值

搜索算法指南 (Searching Algorithm Guide)

Prior to this article, I have written about Binary Search. Check it out if you haven’t seen it. In this article, we will be discussing Interpolation Search, which is an improvement of Binary Search when the values in the sorted array are uniformly distributed.

在本文之前,我已经撰写了有关Binary Search的文章 。 如果您没有看过,请检查一下。 在本文中,我们将讨论插值搜索,它是对已排序数组中的值进行均匀分布时二进制搜索的一种改进。

You might recall that Binary Search is already running in O(log n) time complexity. Can there be any other methods that perform even better? Ummm… partly yes. We will dive into it shortly.

您可能还记得二进制搜索已经以O(log n)时间复杂度运行。 还能有其他方法表现更好吗? 嗯...部分是。 我们将在短期内深入探讨。

什么是插值搜索? (What is Interpolation Search?)

Interpolation Search is another efficient searching technique. This method can outrun binary search in cases where the elements of the array are uniformly distributed. Interpolation Search estimates the position of the key value in the array. This can be achieved by taking into account the smallest and the largest element in the array and the length of the array.

插值搜索是另一种有效的搜索技术。 在数组元素均匀分布的情况下,此方法可以胜过二进制搜索。 插值搜索估计键值在数组中的位置。 这可以通过考虑数组中最小和最大的元素以及数组的长度来实现。

It is based on the thinking that if the key value is larger (closer to the largest element), it’s position is likely located to the end of the array. The same thing goes for a key with a smaller value.

基于以下想法:如果键值较大(更靠近最大元素),则其位置可能位于数组的末尾。 具有较小值的键也是如此。

它是如何工作的? (How Does it Work?)

There are the 6 main steps in doing Interpolation Search, which are:

进行插值搜索有6个主要步骤,它们是:

  1. Estimates the middle position for the array and compares this element to the desired key.估计数组的中间位置,并将此元素与所需键进行比较。
  2. If the key matches the middle element, return the middle location.如果键与中间元素匹配,则返回中间位置。
  3. If the key is smaller than the middle element, then the key can only lie in the left subarray. Focus on the left subarray如果键小于中间元素,则键只能位于左子数组中。 专注于左侧子数组
  4. Else, we move our focus only to the right subarray.否则,我们仅将焦点移到正确的子数组上。
  5. Repeat steps 1, 2, 3, and 4 until the desired key is found or every subarray has been checked.重复步骤1、2、3和4,直到找到所需的键或已检查每个子数组。
  6. If there is no match in the array, return -1如果数组中没有匹配项,则返回-1

插值搜索示例 (Interpolation Search Example)

As usual, the pseudo-code will be provided first before we move to the implementation in different programming languages.

与往常一样,在我们使用不同的编程语言来实现之前,将首先提供伪代码。

Interpolation Search Pseudo-Code

插值搜索伪代码

Now, we will move on to the real code for 3 different languages, Python, C, and JavaScript.

现在,我们将继续使用3种不同语言(Python,C和JavaScript)的真实代码。

Interpolation Search Code in Python

Python中的插值搜索代码

Interpolation Search Code in C

C语言中的插补搜索代码

Interpolation Search Code in JavaScript

JavaScript中的插值搜索代码

插值搜索的时间复杂度 (Time Complexity of Interpolation Search)

In smaller arrays, Interpolation Search is slower than Binary Search. The reason behind this is Interpolation Search requires more computations. However, larger arrays and the ones that are uniformly distributed are Interpolation Search’s forte. The growth rate of Interpolation Search time complexity is smaller compared to Binary Search.

在较小的数组中,插值搜索比二进制搜索慢。 其背后的原因是插值搜索需要更多的计算。 但是,较大的数组和均匀分布的数组是插值搜索的强项。 与二值搜索相比,插值搜索时间复杂度的增长率较小。

The best case for Interpolation Search happens when the middle (our approximation) is the desired key. This makes the best case time complexity is O(1). In the worst-case scenario, we will need to traverse all of the elements in the array, resulting in the O(n) time complexity. The good news is for the average case, the time complexity is as small as O(log log n).

当中间(我们的近似值)是所需的关键点时,就会发生插值搜索的最佳情况。 最好的情况是时间复杂度为O(1)。 在最坏的情况下,我们将需要遍历数组中的所有元素,从而导致O(n)时间复杂度。 好消息是对于一般情况,时间复杂度小至O(log log n)。

结论 (Conclusion)

Summing up, learning how to apply Interpolation Search will enrich your knowledge not only about algorithms but also as a programmer. Undoubtedly, it will have a place in your programming toolkit. However, it should always be remembered:

总结一下,学习如何应用插值搜索不仅可以丰富您的算法知识,还可以作为一名程序员。 毫无疑问,它将在您的编程工具包中占有一席之地。 但是,应始终记住:

  1. Similar to Binary Search, Interpolation Search only works in sorted arrays.与二进制搜索类似,插值搜索仅适用于排序数组。
  2. You need to have direct access to the elements of the array.您需要直接访问数组的元素。

There is no easy way to become an expert programmer, the only available path is by persistently learning about the key concepts one by one. So, if I can understand these concepts, so can you.

成为专家程序员没有简单的方法,唯一可行的途径是持续不断地逐一学习关键概念。 因此,如果我能理解这些概念,那么您也可以。

“The secret to getting ahead is getting started.”

“取得成功的秘诀就是开始。”

— Mark Twain

—马克·吐温

Let’s go to the top together!

让我们一起去顶吧!

Regards,

问候,

Radian Krisno

拉迪安·克里斯诺(Radian Krisno)

翻译自: https://towardsdatascience.com/demystifying-interpolation-search-45dca5c24115

线性插值插值


http://www.taodudu.cc/news/show-994796.html

相关文章:

  • 如果您不将Docker用于数据科学项目,那么您将生活在1985年
  • docker部署flask_使用Docker,GCP Cloud Run和Flask部署Scikit-Learn NLP模型
  • 问卷 假设检验 t检验_真实问题的假设检验
  • 大数据技术 学习之旅_为什么聚焦是您数据科学之旅的关键
  • 无监督学习 k-means_无监督学习-第4部分
  • 深度学习算法原理_用于对象检测的深度学习算法的基本原理
  • 软件本地化 pdf_软件本地化与标准翻译
  • 数据库不停机导数据方案_如何计算数据停机成本
  • python初学者_面向初学者的20种重要的Python技巧
  • 贝叶斯网络建模
  • 数据科学家数据分析师_使您的分析师和数据科学家在数据处理方面保持一致
  • python db2查询_如何将DB2查询转换为python脚本
  • 爱因斯坦提出的逻辑性问题_提出正确问题的重要性
  • 餐厅数据分析报告_如何使用数据科学选择理想的餐厅设计场所
  • 熊猫直播 使用什么sdk_没什么可花的-但是16项基本操作才能让您开始使用熊猫
  • 关系型数据库的核心单元是_核中的数据关系
  • 小程序 国际化_在国际化您的应用程序时忘记的一件事
  • robo 3t连接_使用robo 3t studio 3t连接到地图集
  • 软件需求规格说明书通用模版_通用需求挑战和机遇
  • 一类动词二类动词三类动词_基于http动词的完全无效授权技术
  • 一年了
  • 将DataSet中的操作更新到Access数据库
  • 我喜欢的一首歌--《幸福的瞬间》
  • XForum 里用 Filter 编程实现安全访问控制
  • chedandekaoyan
  • Microsoft好员工的十个标准
  • GARFIELD@11-20-2004
  • SPS用户管理的问题
  • 最近关注的一些东西
  • 吉他谱——单身情歌

线性插值插值_揭秘插值搜索相关推荐

  1. 拉格朗日插值_拉格朗日插值定理的理论基础

    缺失,几乎是不可避免的.只要做数据处理,不可避免的工作就是插值.而插值里面比较常用的方法之一就是拉格朗日插值法,这篇文章就跟大家讲讲拉格朗日插值的理论基础. 为什么需要进行插值 我们进行数据处理的理想 ...

  2. python 插值_三次样条插值在Python中的实现

    什么是三次样条插值 三次样条插值(Cubic Spline Interpolation)简称Spline插值,是通过一系列形值点的一条光滑曲线,数学上通过求解三弯矩方程组得出曲线函数组的过程. 实际计 ...

  3. python缺失值拉格朗日插值_拉格朗日插值-python

    在数据库中,有些数据是异常值或者空值,这些值在分析的时候应该特殊处理,比如最简单的忽略掉或者通过算法推测它的值.其中拉格朗日插值就是通过其他已经知道的值,对x位置缺失的值插入的算法. 假定我们已经知道 ...

  4. 数学建模准备 插值(拉格朗日多项式插值,牛顿多项式插值,分段线性插值,分段三次样条插值,分段三次Hermite插值)

    文章目录 摘要(必看) 0 基础概念 什么是插值 插值用途 什么是拟合 插值和拟合的相同点 插值和拟合的不同点 1 常用的基本插值方法 1.1 多项式插值法 1.1.1 拉格朗日多项式插值法 多项式插 ...

  5. 插值与拟合 (一) : 拉格朗日多项式插值 、Newton插值 、分段线性插值、Hermite插值 、样条插值、 B 样条函数插值、二维插值

    插值:求过已知有限个数据点的近似函数. 拟合:已知有限个数据点,求近似函数,不要求过已知数据点,只要求在某种意义下它在这些点上的总偏差最小. 插值和拟合都是要根据一组数据构造一个函数作为近似,由于近似 ...

  6. 分段二次插值函数表达式_【插值】插值方法原理详解

    插值问题详解 1. 我在具体的应用(如数学建模竞赛)中,常常需要根据已知的函数点进行数据.模型的处理和分析,而通常情况下现有的数据是极少的,不足以支撑分析的进行,这时就需要使用一些数学的方法,&quo ...

  7. Matlab实现线性插值、抛物插值、牛顿插值、拉格朗日插值、分段抛物插值、分段线性插值

    目录 线性插值 原理 流程图 代码 抛物插值 原理 流程图 代码 拉格朗日插值 代码 牛顿插值 原理 代码 分段线性插值 代码 线性插值 原理 流程图 单个点的线性插值代码 X=[0.2 0.4]; ...

  8. arcgispython空间插值_空间分析之插值(转)

    在实际工作中,由于成本的限制.测量工作实施困难大等因素,我们不能对研究区域的每一位置都进行测量(如高程.降雨.化学物质浓度和噪声等级).这时,我们可以考虑合理选取采样点,然后通过采样点的测量值,使用适 ...

  9. 拉格朗日插值的优缺点_拉格朗日插值的优缺点_拉格朗日插值法与牛顿插值法的比较...

    第 1 页 共 7 页 拉格朗日插值法与牛顿插值法的比较 [ 摘 要 ] 在生产和科研中出现的函数是多样的.对于一些函数很难找出其解析表达式.即使在某些情况下,可以写出函 数的解析表达式,但由于解析表 ...

最新文章

  1. 使用Python从PDF导出数据
  2. php think命令用不了,自定义 PHP think 命令无法在命令类文件里面使用 Db 类
  3. 【Flutter】Icons 组件 ( FlutterIcon 下载图标 | 自定义 svg 图标生成 ttf 字体文件 | 使用下载的 ttf 图标文件 )
  4. Double Free浅析
  5. 从贝泰妮的全域消费者运营,看Quick Audience如何链接产品服务商生态
  6. Keil C51软件的使用教程
  7. 关于SVG文件在Firefox中正确显示的研究
  8. java实现动态验证码源代码——绘制验证码的jsp
  9. distributed crawl
  10. OSChina 周五乱弹 —— 如何向妹子解释越位
  11. 第8章 多项式回归与模型泛化 学习笔记上
  12. H5手机转盘抽奖活动游戏页面源码
  13. (附源码)小程序 平衡膳食小程序 毕业设计 250859
  14. 进位位判别法_判断加减法溢出时,可采用判断进位的方式,如果符号位的进位为C...
  15. iphone双重认证关闭不了怎么办_iPhone双重认证怎么关闭?苹果手机关闭双重认证的两种方法[多图]...
  16. JavaCV 制作字符画
  17. 星岚技术 Win10 x64 纯净版 V2021.5【带驱动包】
  18. CPU与存储器连接习题
  19. GGGGGGithub
  20. OCI--学习OCI编程

热门文章

  1. 怎样检测mysql5.5安装成功_64位wiN7系统中装配MySQL5.5.17(测试安装成功哦!)
  2. 【1】MySQL的四种事务隔离级别
  3. 万字总结!腾讯、字节跳动面经已发
  4. 安卓开发必须会的技能!浅谈Android消息机制原理,威力加强版
  5. java----连接池C3p0使用的补充
  6. 解决读写分离过期读的几个方案
  7. myelcipse和maven搭建项目
  8. 初识spring-boot
  9. 关于eclipse中文注释乱码的问题
  10. 所有程序员都应该遵守的11条规则