DEV Community

Cover image for Algorithms and Data Structures: Linear Search
Aleksandar Vasilevsk
Aleksandar Vasilevsk

Posted on • Originally published at codespot.org

Algorithms and Data Structures: Linear Search

As the name says a linear search is a process that starts at the beginning of a list and goes through every element (one item at a time) until it finds the element which is looking for. To find the element which is searching for (for example we are searching for x), a linear search algorithm is comparing every element in the list with the value inside of x, until a match is found or the whole list has been searched. Performance for using linear search in large lists is bad because it makes at most n comparisons, where n is the length of the list. In practice, linear search algorithm is rarely being used because other search algorithms like the binary search algorithm allow significantly faster searching for all but shortlists.

Continue reading...

Latest comments (0)