March 2019
Intermediate to advanced
336 pages
9h 9m
English
The linear search method finds a given value within a collection by sequentially checking every element in the collection. The time complexity of the linear search algorithm is O(n). The binary search algorithm and hash tables perform better than this search algorithm.
The implementation of the linear search method is shown in the following code snippet. The LinearSearch function takes an array of integer elements and findElement int as parameters. The function returns a Boolean true if the findElement is found; otherwise, it returns false:
//main package has examples shown// in Go Data Structures and algorithms bookpackage main// importing fmt packageimport ( "fmt")// Linear Search methodfunc LinearSearch(elements []int, findElement ...
Read now
Unlock full access