Lesson Objective
By the end of this lesson, you will be able to describe the differences between binary and linear searches
You will also be able to show a practical understanding of using a search algorithm
Keywords
Linear - Search - Array - Item - Element - Binary - Median
What is a Linear Search?
Imagine you have a list of numbers, and you want to find if a specific number is in the list. A linear search looks at each number one by one, from the beginning to the end, until it finds the number or checks every number.
Using this information as well as the link on your digital worksheet, describe what a linear search is.
Linear search algorithm can be used in scenarios such as searching for a specific value in a phone book, searching for a name in an unsorted list of contacts, or finding an item in a grocery list.
List of numbers: [2, 5, 8, 12, 14, 19, 25]
Target number: 12 (we want to find this number in the list)
We check each number in the list one by one, comparing it to 12.
When we find 12, we print "Found 12 in the list!" and stop.
If we go through the entire list and don't find 12, we print "12 is not in the list."
Can you find out any advantages and disadvantages of a linear search?
Use the link below to aid your studies and use your Google Slide to answer the question.