In this program, we will create an array of integer elements. Then we will read an item from the user to search into the array using interpolation search and print the index of the item in the array.
The interpolation search is an improved version of binary search. Here we will use the improved formula to calculate the middle element.
Program/Source Code:
The source code to search an item into the array using interpolation search is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created an array of integer elements. Then we read an item from the user to search into the sorted array using an interpolation search mechanism. After that, we printed the index of the item in the array, if the item was found. Otherwise, we printed the "Item not found" message.
need an explanation for this answer? contact us directly to get an explanation for this answer