线性插值算法实现图像

Problem:

问题:

We are given an array arr[] with n elements and an element x to be searched amongst the elements of the array.

给定一个数组arr [],其中包含n个元素和一个要在该数组的元素中搜索的元素x 。

Solution:

解:

Here, we will be performing Interpolation Search to find the element in the array.

在这里,我们将执行插值搜索以找到数组中的元素。

插值搜索 (Interpolation Search )

Interpolation Search is a much better choice of search algorithm than Linear and Binary Search. We can perform a linear search on a very small dataset, a binary search on a large dataset but what if we are given a dataset where we have millions of data rows and columns. Here, the interpolation search comes to the rescue.

插值搜索是比线性和二进制搜索更好的搜索算法选择。 我们可以对非常小的数据集执行线性搜索,对大型数据集执行二进制搜索,但是如果给定的数据集包含数百万个数据行和列,该怎么办。 在这里,插值搜索可以解决。

One of the basic assumptions of this algorithm is similar to that of the Binary Search Algorithm, i.e. the list of elements must be sorted and uniformly distributed.
It has a huge advantage of time complexity over binary search as here, the complexity is O(log log n) whereas, it is O(log n) in binary search in the average case scenario.

该算法的基本假设之一类似于二进制搜索算法,即必须对元素列表进行排序并使其均匀分布。
它的时间比二进制搜索这里复杂的巨大优势,复杂度为O(log日志N),而,它是O(log n)的在平均的情况下二进制搜索。

    Input:
Array: 10, 20, 35, 45, 55, 68, 88, 91
Element to be searched: 68

Terminologies:

术语:

  • ub : upper index of the array

    ub :数组的上索引

  • lb : lower index of the array

    lb :数组的下标

  • x : element to be searched

    x :要搜索的元素

  • pos : the position at which the array is split and is calculated using the following formula,

    pos :数组拆分的位置,并使用以下公式计算得出:

        pos = lb + { [ (ub – lb) / (arr[ub] – arr[lb]) ] * (x – arr[lb]) }
    
    

Basic Algorithm:

基本算法:

  1. Find the value of pos using the above formula

    使用上面的公式找到pos的值

  2. Compare the pos element with the element to be searched

    比较pos元素和要搜索的元素

  3. If the value matches, return the index

    如果值匹配,则返回索引

    Else if

    否则

    x is less than the pos element, new sub-array is the elements before the pos element, and if more than the pos value, then the upper half of the array is a new sub-array.

    x小于pos元素,新的子数组是pos元素之前的元素,如果大于pos值,则数组的上半部分是新的子数组。

  4. Repeat steps 1-4 till the target is reached or when there are no elements left.

    重复步骤1-4,直到达到目标或没有剩余元素为止。

Time Complexity: The time complexities of Interpolation Search Algorithm are,

时间复杂度:插值搜索算法的时间复杂度为

  • Worst case: O(n)

    最坏的情况:O(n)

  • Average Case: O(log log n)

    平均情况:O(log log n)

  • Best case: O(1), when the element is present at pos itself

    最佳情况:O(1),当元素本身位于pos时

  • Space Complexity: O(1)

    空间复杂度:O(1)

C Implementation:

C实现:

#include <stdio.h>
int interpol_search(int arr[], int lb, int ub, int x)
{while ((arr[lb] != arr[ub]) && (x <= arr[ub]) && (x >= arr[lb])) {int pos = lb + (((ub - lb) / (arr[ub] - arr[lb])) * (x - arr[lb]));
if (arr[pos] == x)
return pos;
if (arr[pos] < x)
lb = pos + 1;
else
ub = pos - 1;
}
return -1;
}
int main()
{int arr[] = { 10, 20, 35, 45, 55, 68, 88, 91 };
int n = sizeof(arr) / sizeof(arr[0]);
int x = 68;
int index = interpol_search(arr, 0, n - 1, x);
if (index != -1)
printf("Element %d is present at index %d", x, index);
else
printf("Element %d not found in the list!", x);
return 0;
}

Output

输出量

Element 68 is present at index 5

翻译自: https://www.includehelp.com/c-programs/implement-interpolation-search-algorithm.aspx

线性插值算法实现图像

线性插值算法实现图像_C程序实现插值搜索算法相关推荐

  1. 用线性插值算法实现图像缩放

    用线性插值算法实现图像缩放 猛禽[Mental Studio](个人专栏)(BLOG) http://mental.mentsu.com 在Windows中做过图像方面程序的人应该都知道Windows ...

  2. 视频图像处理基础知识0(双线性插值算法进行图像缩放)【转】

    转自:http://blog.csdn.net/times_poem/article/details/51395781 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 双线性插 ...

  3. bayer插值算法(3):高质量线性插值算法

    目录 前言 插值算法 高质量插值算法 代码示例 前言 相机生成的图像一般是bayer阵列的raw图,这时候如果转换成我们需要的rgb图像,就需要对应的bayer插值算法将丢失的rgb信息通过算法补齐 ...

  4. 图像几何变换时为何要用到插值算法?_图像超分辨率技术-简介

    这篇是我之前的课程报告,格式传上来乱了,有时间我会调整,我先把pdf版本放在最前面,建议直接看pdf. 一. 定义与分类 超分辨率复原技术的基本思想是釆用信号处理的方法,在改善图像质量的同时,重建成像 ...

  5. 欧拉角与四元数互转,及四元数slerp球面线性插值算法

    欧拉角与四元数互转,及四元数slerp球面线性插值算法 1. 欧拉角与四元数是什么? 2. 源码 2.1 欧拉角类 2.2 四元数类 2.3 欧拉角与四元数互转及球面线性插值算法 参考 1. 欧拉角与 ...

  6. OpenCV图像缩放resize各种插值方式的比较

    OpenCV图像缩放resize各种插值方式的比较 目录 OpenCV图像缩放resize各种插值方式的比较 1. resize函数说明 2.各种插值方式的比较 2.1 INTER_NEAREST(最 ...

  7. 【图像处理】基于半色调技术的图像打印程序(Image Printing Program Based on Halftoning)

    实验要求   本实验后面的图像给出了用点模式近似表示的10 个灰度级.每一个灰度级用一个3 x 3 的黑白点模式表示.用黑点全部填充的3 x 3 区域近似表示灰度级为0 的黑色灰度级,全部填充白点的3 ...

  8. 高富帅的颜色插值方法:在视觉感知线性变化的色彩空间中进行颜色插值

    大多数情况下,我们会给材质提供一个Color值,来整体控制对象的颜色.一般都是使用 Color * ( TextureColor + LightColor) 来做. 颜色值动画是常规的动画特效之一,最 ...

  9. DM642图像平移程序学习

    DM642的图像平移程序,刚开始没明白为什么平移要分为两个半屏来平移,后来琢磨了一下不知道理解对不对,先上程序: /*确定图像的参数*/ int numPixels = 720;//每行720个像素 ...

最新文章

  1. 2022-2028年中国水处理分离膜行业市场现状调研及市场需求潜力报告
  2. c++返回值 注意事项
  3. linux wget下载、断点续传
  4. 第二阶段_第三小节_C#基础
  5. 并行、并发,两者的区别
  6. 中国移动IM-飞信-0802上线新版本 试用手记
  7. 赛锐信息:FlexBroswer,一劳永逸解决业务系统Flash问题
  8. ParticleSystem的使用
  9. Android 编译时出现r cannot be resolved to a variable
  10. 一条SQL语句查询出成绩名次 排名 (转)
  11. hive on spark 安装配置 详解
  12. JDBC-Web抽取公共的增删改方法
  13. set_global_opts在PyEcharts中实现全局配置项
  14. word打开html显示空白,电脑打开Word文档内容显示不全或显示空白怎么解决
  15. ​Aruba 无线控制器本地账号登录密码重置
  16. [生存志] 第74节 孔子集结诗经
  17. 社群空间站一键发布微信群精品优质社群的搜索和发布平台源码
  18. 怎么查自己电脑服务器信息吗,如何查看自己电脑的服务器
  19. QA - 有两种药片A和B,外观一样功效不同,每次需要吃一个A+B;拿出来2A+B,问该怎么吃?
  20. 也门亚丁一炼油厂爆炸起火造成数人受伤

热门文章

  1. linux将txt文件复制为bak,Linux命令:cp (copy)复制文件或目录
  2. 计算机演示题打不开,大神为你演示win7系统计算机上右键管理打不开的还原技巧...
  3. linux eclipse svn插件安装,Linux上Eclipse安装SVN插件和安装JavaHL
  4. Canvas-图片旋转
  5. jquery点击非div区域隐藏div
  6. 基于 Webpack2、Vue2、iView2 的可视化脚手架 iView Cli 发布 2.0 版本
  7. 课时106.边框练习(理解)
  8. vue+elementUI 添加多个可以全选的多选框
  9. cf1208G Polygons 欧拉函数
  10. hibernate cascade的真正含义