function interpolation_search(arr, item) {
let low = 0;
let high = arr.length - 1;
let mid = -1;
let index = -1;
while (low <= high) {
mid = low + ((parseInt((high - low) / (arr[high] - arr[low]))) * (item - arr[low]));
if (arr[mid] == item) {
index = mid;
break;
}
else {
if (arr[mid] < item) {
low = mid + 1;
}
else {
high = mid - 1;
}
}
}
return index;
}
const arr = [2, 5, 6, 8, 9, 20, 34, 36, 40, 46, 51, 55, 61, 72, 86, 97];
const item = 51;
const index = interpolation_search(arr, item);
if (index != -1) {
console.log("index = " + index);
}
else {
console.log("Not found");
}
/*
run:
index = 10
*/