日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2023/12/1 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 线性插值算法实现图像_C程序实现插值搜索算法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

線性插值算法實現(xiàn)圖像

Problem:

問題:

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

給定一個數(shù)組arr [],其中包含n個元素和一個要在該數(shù)組的元素中搜索的元素x 。

Solution:

解:

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

在這里,我們將執(zhí)行插值搜索以找到數(shù)組中的元素。

插值搜索 (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.

插值搜索是比線性和二進(jìn)制搜索更好的搜索算法選擇。 我們可以對非常小的數(shù)據(jù)集執(zhí)行線性搜索,對大型數(shù)據(jù)集執(zhí)行二進(jìn)制搜索,但是如果給定的數(shù)據(jù)集包含數(shù)百萬個數(shù)據(jù)行和列,該怎么辦。 在這里,插值搜索可以解決。

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.

該算法的基本假設(shè)之一類似于二進(jìn)制搜索算法,即必須對元素列表進(jìn)行排序并使其均勻分布。
它的時間比二進(jìn)制搜索這里復(fù)雜的巨大優(yōu)勢,復(fù)雜度為O(log日志N),而,它是O(log n)的在平均的情況下二進(jìn)制搜索。

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

Terminologies:

術(shù)語:

  • ub : upper index of the array

    ub :數(shù)組的上索引

  • lb : lower index of the array

    lb :數(shù)組的下標(biāo)

  • x : element to be searched

    x :要搜索的元素

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

    pos :數(shù)組拆分的位置,并使用以下公式計算得出:

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

Basic Algorithm:

基本算法:

  • Find the value of pos using the above formula

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

  • Compare the pos element with the element to be searched

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

  • 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元素,新的子數(shù)組是pos元素之前的元素,如果大于pos值,則數(shù)組的上半部分是新的子數(shù)組。

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

    重復(fù)步驟1-4,直到達(dá)到目標(biāo)或沒有剩余元素為止。

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

    時間復(fù)雜度:插值搜索算法的時間復(fù)雜度為

    • 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),當(dāng)元素本身位于pos時

    • Space Complexity: O(1)

      空間復(fù)雜度:O(1)

    C Implementation:

    C實現(xiàn):

    #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;elseub = 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);elseprintf("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

    線性插值算法實現(xiàn)圖像

    總結(jié)

    以上是生活随笔為你收集整理的线性插值算法实现图像_C程序实现插值搜索算法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。