Jump to content

4.2.2.1 Linear Search

From Computer Science Knowledge Base
Revision as of 22:07, 11 July 2025 by Mr. Goldstein (talk | contribs) (Created page with "=== 4.2.2.1 Linear Search === ''(Difficulty Note: This is a very intuitive and accessible concept for 7th graders.)'' '''Linear Search''' is the simplest way to find something. It's like looking for a book in a messy pile without any order. You start at the very beginning of the list of items and check each item one by one until you find what you're looking for, or until you reach the end of the list. '''How it works:''' # Start at the first item. # Is this the item y...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

4.2.2.1 Linear Search

(Difficulty Note: This is a very intuitive and accessible concept for 7th graders.)

Linear Search is the simplest way to find something. It's like looking for a book in a messy pile without any order. You start at the very beginning of the list of items and check each item one by one until you find what you're looking for, or until you reach the end of the list.

How it works:

  1. Start at the first item.
  2. Is this the item you're looking for?
    • If Yes, you found it! Stop.
    • If No, move to the next item.
  3. Keep doing this until you find the item or run out of items to check.

Example: Imagine you have a list of numbers: [5, 12, 3, 8, 15, 7] and you're looking for the number 8.

  • Check 5 (No)
  • Check 12 (No)
  • Check 3 (No)
  • Check 8 (Yes!) – You found it!

When is it used? Linear search works well for short lists or lists that are not sorted in any particular order. It's easy to understand and program. However, if you have a very long list, it can be slow because you might have to check every single item.

Bibliography:

Further Reading: