线性插值算法实现图像_C程序实现插值搜索算法

线性插值算法实现图像

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

线性插值算法实现图像

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/379559.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

hdu 1197

地址&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid1197 题意&#xff1a;求一个数转换成10&#xff0c;12&#xff0c;16进制后各个位上的数的和是否相等。 mark&#xff1a;模拟进制转换。 代码&#xff1a; #include <stdio.h>int zh(int a, int n) {int su…

linux系统编程---线程总结

线程总结1 线程的实现线程创建线程退出线程等待线程清理2 线程的属性线程的分离线程的栈地址线程栈大小线程的调度策略线程优先级3 线程的同步互斥锁读写锁条件变量信号量线程是系统独立调度和分配的基本单位。同一进程中的多个线程将共享该进程中的全部系统资源&#xff0c;例…

博客上一些项目相关源码链接

GitHub&#xff1a;https://github.com/beyondyanyu/Sayingyy

重新开启Ctrl+Alt+Backspace快捷键

UBUNTU老用户知道CtrlAltBackspace这个快捷键是用来快速重启X的在9.04中被默认关闭了&#xff0c;那如何来打开它呢&#xff1f;在终端中输入&#xff1a;sudo gedit /etc/X11/xorg.conf在其中加入&#xff1a;Section “ServerFlags”Option “DontZap” “false”EndSection退…

Java LocalDate类| 带示例的getDayOfYear()方法

LocalDate类的getDayOfYear()方法 (LocalDate Class getDayOfYear() method) getDayOfYear() method is available in java.time package. getDayOfYear()方法在java.time包中可用。 getDayOfYear() method is used to get the day-of-year field value of this LocalDate obje…

火腿三明治定理

定理&#xff1a;任意给定一个火腿三明治&#xff0c;总有一刀能把它切开&#xff0c;使得火腿、奶酪和面包片恰好都被分成两等份。 而且更有趣的是&#xff0c;这个定理的名字真的就叫做“火腿三明治定理”&#xff08;ham sandwich theorem&#xff09;。它是由数学家亚瑟•斯…

如何给Linux操作系统(CentOS 7为例)云服务器配置环境等一系列东西

1.首先&#xff0c;你得去购买一个云服务器&#xff08;这里以阿里云学生服务器为例&#xff0c;学生必须实名认证&#xff09; 打开阿里云&#xff0c;搜索学生服务器点击进入即可 公网ip为连接云服务器的主机 自定义密码为连接云服务器是需要输入的密码 购买即可 点击云服…

Linux系统编程---I/O多路复用

文章目录1 什么是IO多路复用2 解决什么问题说在前面I/O模型阻塞I/O非阻塞I/OIO多路复用信号驱动IO异步IO3 目前有哪些IO多路复用的方案解决方案总览常见软件的IO多路复用方案4 具体怎么用selectpollepolllevel-triggered and edge-triggered状态变化通知(edge-triggered)模式下…

[转帖]纯属娱乐——变形金刚vs天网

[转帖]变形金刚2的影评-《变形金刚3 天网反击战》有一个问题困扰了我足足二十年&#xff1a;为什么汽车人要帮地球人&#xff1f;光用“所有有感知的生物都应享有自由”这个法则是根本说不过去的&#xff0c;因为猪也有感知&#xff0c;但人类就把猪圈养起来&#xff0c;随意杀…

c#中textbox属性_C#.Net中的TextBox.MaxLength属性与示例

c#中textbox属性Here we are demonstrating use of MaxLength property of TextBox. 在这里&#xff0c;我们演示了TextBox的MaxLength属性的使用。 MaxLength property of TextBox is used to set maximum number of character that we can input into a TextBox. Limit of M…

IIS7 MVC网站生成、发布

(1)生成。 确保System.Web.Mvc.dll在bin目录下 (2)发布网站到文件系统 (3)在IIS中为网站添加应用程序池&#xff08;一个虚拟目录&#xff0c;一个应用程序池&#xff09; (4)添加在默认网站下添加虚拟目录 &#xff08;5&#xff09;转换为应用程序 至此&#xff0c;部署完毕 …

标题:明码

转载&#xff1a;https://blog.csdn.net/u011747888/article/details/79781040 标题&#xff1a;明码 汉字的字形存在于字库中&#xff0c;即便在今天&#xff0c;16点阵的字库也仍然使用广泛。 16点阵的字库把每个汉字看成是16x16个像素信息。并把这些信息记录在字节中。 一…

C语言多维数组

文章目录多维数组数组名下标指向数组的指针作为函数参数的多维数组指针数组小结多维数组 如果某个数组的维数超过1&#xff0c;它就被称为多维数组&#xff0c;例如&#xff0c;下面这个声明&#xff1a; int matrix[6][10]创建了一个包含60个元素的矩阵。但是&#xff0c;它…

ubuntu路由器联网_路由器及其协议简介| 联网

ubuntu路由器联网路由器简介 (Introduction to Router) Routers are network layer devices. Data on the network layer is known as packets. Routers work to forward packets from one network to another. Routers also maintain the address table. 路由器是网络层设备。…

XPath学习:轴(5)——descendant-or-self

XPath 是一门在 XML 文档中查找信息的语言。XPath 可用来在 XML 文档中对元素和属性进行遍历。 XPath 是 W3C XSLT 标准的主要元素&#xff0c;并且 XQuery 和 XPointer 同时被构建于 XPath 表达之上。 推荐一个挺不错的网站&#xff1a;http://www.zvon.org/xxl/XPathTutorial…

linux设备驱动开发---平台设备驱动程序

文章目录1 平台驱动程序2 平台设备2.1 资源和平台数据1 设备配置---废弃的旧方法资源平台数据声明平台设备2 设备配置---推荐的新方法3 设备、驱动程序和总线匹配OF风格ACPIID表匹配匹配平台设备的名字和平台驱动的名字平台设备和平台驱动程序如何匹配4 Platfrom架构驱动程序有…

标题:乘积尾零

标题&#xff1a;乘积尾零 如下的10行数据&#xff0c;每行有10个整数&#xff0c;请你求出它们的乘积的末尾有多少个零&#xff1f; 5650 4542 3554 473 946 4114 3871 9073 90 4329 2758 7949 6113 5659 5245 7432 3051 4434 6704 3594 9937 1173 6866 3397 4759 7557 3070…

Robots.txt指南

Robots.txt指南当搜索引擎访问一个网站时&#xff0c;它首先会检查该网站的根域下是否有一个叫做robots.txt的纯文本文件。Robots.txt文件用于限定搜索引擎对其 网站的访问范围&#xff0c;即告诉搜索引擎网站中哪些文件是允许它进行检索(下载)的。这就是大家在网络上常看到的“…

fwrite函数的用法示例_C语言中的fwrite()函数(带有示例)

fwrite函数的用法示例C中的fwrite()函数 (fwrite() function in C) Prototype: 原型&#xff1a; size_t fwrite(void *buffer, size_t length, size_t count, FILE *filename);Parameters: 参数&#xff1a; void *buffer, size_t length, size_t count, FILE *filenameRetu…

标题:递增三元组

标题&#xff1a;递增三元组 给定三个整数数组 A [A1, A2, … AN], B [B1, B2, … BN], C [C1, C2, … CN]&#xff0c; 请你统计有多少个三元组(i, j, k) 满足&#xff1a; 1 < i, j, k < NAi < Bj < Ck 【输入格式】 第一行包含一个整数N。 第二行包含N个整…