strategy linear search let' try our hand at developing search algorithm using simple "be the computerstrategy suppose that gave you page full of numbers in no particular order and asked whether the number is in the list how would you solve this problemif you are like most peopleyou would simply scan down the list comparing each value to when you see in the listyou quit and tell me that you found it if you get to the very end of the list without seeing then you tell me it' not there this strategy is called linear search you are searching through the list of items one by one until the target value is found this algorithm translates directly into simple code def search(xnums)for in range(len(nums))if nums[ =xitem foundreturn the index value return return - loop finisheditem was not in list this algorithm was not hard to developand it will work very nicely for modest-sized lists for an unordered listthis algorithm is as good as any the python in and index operations both implement linear searching algorithms if we have very large collection of datawe might want to organize it in some way so that we don' have to look at every single item to determine whereor ifa particular value appears in the list suppose that the list is stored in sorted order (lowest to highestas soon as we encounter value that is greater than the target valuewe can quit the linear search without looking at the rest of the list on averagethat saves us about half of the work butif the list is sortedwe can do even better than this strategy binary search when list is orderedthere is much better searching strategyone that you probably already know have you ever played the number guessing gamei pick number between and and you try to guess what it is each time you guessi will tell you if your guess is correcttoo highor too low what is your strategyif you play this game with very young childthey might well adopt strategy of simply guessing numbers at random an older child might employ systematic approach corresponding to linear searchguessing until the mystery value is found of coursevirtually any adult will first guess if told that the number is higherthen the range of possible values is - the next logical guess is each time we guess the middle of the remaining numbers to try to narrow down the possible range this strategy is called binary search binary means twoand at each stepwe are dividing the remaining numbers into two parts we can employ binary search strategy to look through sorted list the basic idea is that we use two variables to keep track of the endpoints of the range in the list where the item could be initiallythe target could be anywhere in the listso we start with variables low and high set to the first and last positions of the listrespectively