Linear Search

Cards (3)

  • Linear Search works by:
    • To start from the beginning of the data set
    • Compare the search item with the first value
    • Search sequentially with the next value
    • Repeat until search item is found and then stop
    • Or return False if item is not found
  • Code for linear search:
  • Advantages and Disadvantages of linear search:
    +
    • Data does not need to be in order
    • Quick for a small set of data
    -
    • Takes a long time for a large set of data
    • Not efficient