linear search

Finding an item by checking each element in turn from the start until it matches or the list ends.

In more detail

Linear search works on any list, sorted or not, and costs O(n) in the worst case. Python's `in` operator on a list is a linear search. When you search the same data repeatedly, a set, dict or sorted list with binary search is usually far faster.

Example

'zara' in users  # checks every name before answering False

Related terms

Taught in

References