'Interpolation Search in
Hello i try to implement interpolation search. But for some reason it does not work with the last element of a integer array.
int interPolSearch(int arr[], int n, int k, int criticalCounter)
while (arr[r] != arr[l] && k >= arr[l] && k <= arr[r]) //while the lowest index is smaller or equal to the upper bound
{
m = l + ((r - l) / (arr[r] - arr[l])) * (k - arr[l]); //start the search with this formula
if (k == arr[m]) //if the key was found in the array then return the index value
{
criticalCounter++;
printf("The index of the key is: %d\n", m);
printf("Interpolation search performed the critical operation: %d times\n", criticalCounter);
return m;
}
else if (k < arr[m])
{
r = m - 1; //if the key is smaller than m split the array again
criticalCounter++;
}
else
{
(l = m + 1); //if the key is bigger go through the upper half of the array
criticalCounter++;
}
}
printf("The value was not found\n");
return -1; //if the key is not found return -1
}
In my implementation in the main function it looks like this
void genSortArr(int arr[], int n)
{
for (int i = 0; i < n; i++)
{
arr[i] = i + 1;
}
}
#define MAX_INPUT 100000
int main()
{
int mid, key;
int arr[MAX_INPUT];
scanf("%d", &len);
genSortArr(arr, len)
mid = (len - 1);
key = Arr[mid];
interPolSearch(Arr, len, key, criticalCounter);
}
For some reason it cannot find the search value. (Where the key is the last value of the array, len the length of the array.)
Solution 1:[1]
Would this have a negative impact on connection pooling ?
Yes. The connection pool is partitioned by connection string, so you would have a connection pool per user. But if you limit the connection pools size, the impact may not be material.
Alternatively you can call sp_set_session_context after connecting to add data to the session identifying the end user.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Browne - Microsoft |
