Go Language Data Search Algorithms
Published: 2024-01-30 13:47:45



Greetings to everyone,

In this article, I will try to explain the most famous data search algorithms in Go language.

_You can access the entire source code from the repo below. If you can improve performance or add new sorting techniques, I would be very happy._


![Git Hub](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rxge7a58gzl7azytzzk4.JPG)

     https://github.com/MuratTunc/DataStructersGo/tree/main

**_Linear Search_**

Array: Sorted or non sequential
Algorithm: All array elements are checked sequentially, starting from the first element. The process ends when the searched number is found; otherwise, the entire array is scanned.

_N-->Array size
Worst case-->2N+1 comparisons_
_The time complexity of linear search is O(n)_


![Linear Serach](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lv37k2yr0hyj4jtq4rut.JPG)





------------------------------------------------------------------


**_Sentinel Linear Search_**


Array: Sorted or non sequential
Algorithm: The number of comparisons are less in _sentinel linear_ search than _linear search_. The difference from linear search is to reduce the number of comparisons.

_N-->Array size
Worst case-->N+2 comparisons
The time complexity of Sentinel Linear Search O(n)._

![Sentinel Linear Search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/edasnydvsiqiyrkcceei.JPG)


 



------------------------------------------------------------------



**_Jump Search_**

Array: Sorted
Algorithm: The aim is to reduce the number of comparisons and switch to the linear search algorithm by reducing the scanning area. The block size that determines the jump distance must be determined. The jumping process continues until a number greater than the searched element is found. When a number greater than the searched element is found, linear search is applied to the last piece in the background.

The complexity of Sentinel Jump Search is O(√N).(Worst Case)



![Jump Search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1iudijlhhw7ndi300hxr.JPG)

------------------------------------------------------------------

**_Binary Search_**

Array: Sorted
Algorithm: The target number is compared with the middle element of the array, and if it is equal to the middle element, the operation is successful and the fastest result is obtained.
If it is not equal to the middle element, it is checked.
    

- If it is less than the middle element, a new search is started in the left half of the array.
-     If it is larger than the middle element, the search starts in the right half of the array.




_N-->Array size
The average time case complexity is O(logN)
Best Case Time Complexity of Binary Search Algorithm: O(1)_





![Binary Search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hmq05mg6d50ti6cnhavp.JPG)

------------------------------------------------------------------

**Interpolation Search**

Array: Sorted
Algorithm: Dynamically adjusts the search range using a formula. Binary Search always goes to the middle element to check but Interpolation Search may go to different locations according to the value of the key being searched.


![Interpolation Search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2p1m8m86856a2oaqbjaq.JPG)



------------------------------------------------------------------

_During this work, of course, I benefited from many open internet resources and tested all the codes. I will continue to improve as I have time._