# Serial and binary search algorithm

If no match is found, then the process will return the appropriate message. Serial search is fairly simple to code. For example the pseudo-code below shows the algorithm in action.

Each item is checked until either a match is found or the loop ends and the 'return 'no match found' is reached. Good performance over small to medium lists.

Computers are now very powerful and so checking potentially every element in the list for a match may not be an issue with lists of moderate length. The list does not need to be in any order. Other algorithms only work because they assume that the list is ordered in a certain way.

Serial searching makes no assumption at all about the list so it will work just as well with a randomly arranged list as an ordered list.

Not affected by insertions and deletions. If the list is random, then linear is the only way 5. If the list is skewed so that the most often searched items are placed at the beginning, then on average, a linear search might be better.

Challenge see if you can find out one extra fact on this topic that we haven't already told you. Click on this link: Revision resources include exam question practice and coursework guides. Topics include network systems, database, data communications, legal issues such as the Data Protection Act, measurement and control, the OSI model along with the ethics and social effects of ICT at work and home..

Sometimes, you may be doing a binary search without realising it. Example You want to find Samuel Jones in the local telephone book. Ask yourself, should this person be to the left or to the right. Repeat this procedure until you find the page where the entry should be and then either apply the same process to columns, or just search linearly along the names on the page as before. Linear search also referred to as sequential search looks at each element in sequence from the start to see if the desired element is present in the data structure.

When the amount of data is small, this search is fast. Its easy but work needed is in proportion to the amount of data to be searched. Doubling the number of elements will double the time to search if the desired element is not present.

Binary search is efficient for larger array. In this we check the middle element. If the value is bigger that what we are looking for, then look in the first half;otherwise,look in the second half.

Repeat this until the desired item is found. The table must be sorted for binary search. It eliminates half the data at each iteration. If we have elements to search, binary search takes about 10 steps, linear search steps. Binary Search finds the middle element of the array. Checks that middle value is greater or lower than the search value. If it is smaller, it gets the left side of the array and finds the middle element of that part.

If it is greater, gets the right part of the array. It loops the operation until it finds the searched value. Or if there is no value in the array finishes the search. Also you can see visualized information about Linear and Binary Search here: Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site the association bonus does not count.

Would you like to answer one of these unanswered questions instead? Email Sign Up or sign in with Google. What is the difference between Linear search and Binary search? Bill the Lizard k Please read the appropriate sections in your course material which, has hopefully, been selected and prepared by your instructor s.

Failing that, a general wikipedia, c2 or google search can answer may of these sort of questions.