In this program, we will create an integer array and read elements from the user. Then we will search the given item in an array using interpolation search and print the appropriate message on the console screen.
Interpolation Search: The interpolation search is used to search items into the sorted array, it is similar to binary search but the calculation to find the middle element is different. We can say that it is the improved version of binary search.
Program/Source Code:
The source code to search an item in the array using interpolation search is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt package that includes the files of package fmt then we can use a function related to the fmt package.
In the main() function, we created an array arr and read elements from the user. Then we searched items in an array using interpolation search. After that, If the item is found in the array then print the index of an item otherwise print the "Item not found in array" message on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer