mirror of
https://github.com/dholerobin/Lecture_Notes.git
synced 2025-07-01 13:06:29 +00:00
Update InterpolationSearch.md
This commit is contained in:
parent
4ae083bca1
commit
09b5b8d3ef
@ -10,7 +10,7 @@ Interpolation is a well-known concept in mathematics, which is used in many fiel
|
||||
|
||||
We are given that a line passes through two points $(x_1, y_1)$ & $(x_2, y_2)$. Now, we are given a value $y$ and we are asked to find $x$ such that $(x,y)$ is on the line.
|
||||
|
||||

|
||||

|
||||
|
||||
Now, by the equation to find a slope, below formula can be used to find $x$,
|
||||
|
||||
@ -24,7 +24,7 @@ In order to find a formula for arrays, we need to have some characteristics of d
|
||||
|
||||
Let say our array values follow a linear distribution, i.e. if we put indexes on $x$ axis and corresponding array values on $y$ axis, then it roughly creates a line. For example, given array `[0,2,4,6,8,10,12]` exactly follows linear distribution.
|
||||
|
||||

|
||||

|
||||
|
||||
If you condsider index as $x$ values and array values as $y$, then for three points $(high,arr[high])$, $(low,arr[low])$, $(x,key)$ the formula turns out to be as below:
|
||||
|
||||
@ -59,8 +59,8 @@ In case if the data roughly(not exactly) creates a line, then also interpolation
|
||||
|
||||
Let's have an example run for array `[0 1 2 4 9 11 14 15 16 19]` and key = 16,
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
|
||||
```cpp
|
||||
|
Loading…
x
Reference in New Issue
Block a user