CS 022A Lecture Notes - Lecture 13: Linear Search, Binary Search Algorithm
Document Summary
Searching through the list one by one until target value found. Linear search starts at the beginning examining one item after another. Searching is a very common programming problem -- the process of looking for a particular value in a collection. Python provides a number of built in search related methods/operations. Two possible outcomes -- the main loop with two ending conditions. Linear search is successful --key is found. Linear search failed -- key does not exist in data. Algorithm stop either when we have found the item or when we have looked at all the items and not found a match. A linear search is the most basic algorithm for finding a specific value within a list or an array. Basically, the algorithm searches sequentially through the list checking every item until you find the specified value. In the worst case linear search will have to check every single item in the list.