We use cookies on this site to enhance your user experience

Aug 29 2019, 9:28 AM PST 2 min

The Linear Search is a Data Searching algorithm. Linear search is the simplest searching algorithm which uses a brute-force method of checking every element in the list in order until the proper result is found.


  1. Check if current element is equivalent to search query
    • If it is, return current element position and end search
    • If not, do nothing
  2. Go on to next element and repeat

Example Code

function linear_search(tab, query)
    --Go through every position in the table
    for i, v in ipairs(tab) do
        --if the current element is the query
        if v == query then
            --return its position
            return i
  • search