Skip to main content

Posts

Interpolation Search

 Let's begin! Interpolation search works better than Binary Search for a Sorted and Uniformly Distributed array. Binary Search goes to the middle element to check irrespective of search-key. On the other hand, Interpolation Search may go to different locations according to search-key. pos = lo + [ (x-arr[lo])*(hi-lo) / (arr[hi]-arr[Lo]) ] The idea of formula is to return higher value of pos When element to be searched is closer to arr[hi]. And Smaller value when closer to arr[lo] pos = lo + [ (x-arr[lo])*(hi-lo) / (arr[hi]-arr[Lo]) ] arr[] ==> Array where elements need to be searched x     ==> Element to be searched lo    ==> Starting index in arr[] hi    ==> Ending index in arr[]

Binary Search

 Let's begin! Binary Search is a Searching Algorithm with logarithmic time complexity. It need the list to be sorted,  form the sorted list it goes to the element at the middle.  If the middle element is equal to target it returns true. Else if the target element is less than the middle range then it changes it's range from low to middle and call the function with new parameters. Else if the target element is greater than the middle range then it changes it's range from middle to high and call the function with new parameters. Else returns false.

Linear Search

 Let's begin! Linear Search is a Searching Algorithm which search an element inside a list in linear time. It search element from the starting of a list till the end of the list one by one.  If the element is found it returns True. Else it returns False.