What is the formula used for calculating the position in interpolation search? (x = element being searched, A[] = input array, low and

Trần Vũ

New member
What is the formula used for calculating the position in interpolation search?
(x = element being searched, A[] = input array, low and high are the leftmost and rightmost index of A[] respectively)
A. ((x – A[low]) * (high – low)) / (A[high] – A[low])
B. high + ((x – A[low]) * (high – low)) / (A[high] – A[low])
C. low + ((x – A[low]) * (high – low)) / (A[high] – A[low])
D. x + ((x – A[low]) * (high – low)) / (A[high] – A[low])
 
Answer: c
Explanation: For calculating the position after each iteration in interpolation search we use the formula low + ((x – A[low]) * (high – low)) / (A[high] – A[low]). Then the value at the calculated position is compared with the element being searched.
 

Tìm kiếm

Back
Top