Interpolation Search and Exponential Search
3. Interpolation Search:-
The Interpolation Search is an improvement over Binary Search for instances, where the values in a sorted array are uniformly distributed. Binary Search always goes to the middle element to check. On the other hand, interpolation search may go to different locations according to the value of the key being searched. For example, if the value of the key is closer to the last element, interpolation search is likely to start search toward the end side.
To find the position to be searched, it uses following formula.
pos = lo + [ (x-arr[lo])*(hi-lo) / (arr[hi]-arr[Lo]) ]
Algorithm
Step1: In a loop, calculate the value of “pos” using the probe position formula.
Step2: If it is a match, return the index of the item, and exit.
Step3: If the item is less than arr[pos], calculate the probe position of the left sub-array. Otherwise calculate the same in the right sub-array.
Step4: Repeat until a match is found or the sub-array reduces to zero.
Time complexity (if the elements are uniformly distributed):-O(log(log(n)))
Time complexity (if numerical values of the keys increase exponentially):-O(n)
4. Exponential Search
Exponential Search also known as finger search, searches for an element in a sorted array by jumping 2^i
elements every iteration where i represents the value of loop control variable, and then verifying if the search element is present between
last jump and the current jump.
Algorithm
Step 1:- Start with value i=1
Step 2:- Check for condition i < n and Array[i]<=key, where n is the number of elements in the array and key is the element being searched
Step 3:- Increment value of i in powers of 2, that is, i=i*2
Step 4:- Keep on incrementing the value of i until the condition is satisfied
Step 5:- Apply binary on the range i/2 till the end of Array - binarySearch(Array, i/2,min(i,n-1))
Time complexity :-O(logn)
NYC....got crystal clear understanding of the concept
ReplyDeleteExcellent work
ReplyDelete๐Great
ReplyDeleteThanks for clearing this concept!!!
ReplyDeleteGreat blog
ReplyDeletevery interesting information ๐
Nice๐ซ very easy to understand
ReplyDeleteVery well explained!!
ReplyDeleteTerrific Explanation ๐๐ป
ReplyDeleteGreat Work Man๐
ReplyDeleteNice
ReplyDeleteExcellent
ReplyDeleteGreat work ๐
ReplyDeleteGreat work
ReplyDeleteGreat work
ReplyDeleteVery helpful
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGreat work ๐
ReplyDeleteGreat work
ReplyDeleteVery helpful!!
ReplyDeleteVery nicely explained!! Great work!!
Nice explanation
ReplyDeleteGreat work๐
ReplyDeleteNicely explained
ReplyDeleteVery well explained
ReplyDeleteThank you for wonderful information!
ReplyDeleteVery good explanations all doubt cleared.
ReplyDeleteVery well explained
ReplyDeleteVery well explained
ReplyDeleteTruly helpful!
ReplyDelete