Facebook LinkedIn Discord Youtube E-mail

Notes

Algorithms ▸
Linear Search Algorithm - bjelDark

Animation | Rigging | UE | Unity | Scripts | Photography | MISC

Category selection

Linear Search Algorithm

Simplest search algorithm, using plain brute force.

Finds an index of searched item (target) in unsorted array.

Starts from left-most element, compares it with target - if matched, returns index of that element; if not, moves to next one, compares it...

If last element is reached, and target is not found (meaning it doesn't exist in searched array), returns error message (or desired outcome).

Algorithm's Complexity: Big O(n)

Best case (if target is first element in array) - Big O(1)

Worst case (if target is last element in array) - Big O(n)

On average, it will inspect half of elements in list.

  Linear Search [Python Implementation]: