Linear search

Cards (5)

  • On what types of lists does linear search work?
    It works on both sorted and unsorted lists.
  • When is linear search most efficient?
    It is efficient for small lists or when searching infrequently.
  • What are the steps of the linear search algorithm?
    1. Start at the beginning of the list.
    2. Compare the current element with the target value.
    3. If they match, return the current position.
    4. If they don't match, move to the next element.
    5. Repeat until the element is found or the end of the list is reached.
    6. If the end is reached without a match, return "not found".
  • What is a disadvantage of using linear search?

    It is slow for large datasets.
  • What is the primary advantage of linear search?
    It is simple to understand and implement.