Comparison of searches
Different algorithmA sequence of logical instructions for carrying out a task. In computing, algorithms are needed to design computer programs. might be best used in different situations. For example, sometimes an algorithm won’t work with a particular set of dataUnits of information. In computing there can be different data types, including integers, characters and Boolean. Data is often acted on by instructions., and in some instances one algorithm will be much quicker or more efficient than another.
Serial search
One of the main advantages of a serial searchA simple method of searching, in which the search moves from one item to the next in sequence, until either a match is found or end of the data is reached with no match found. is that it is a very simple algorithm, which makes it very easy to write a computer programSequences of instructions for a computer. to carry it out. It can also be used on any set of data regardless of data typeThe format in which a variable or constant holds data, such as ‘integer’ or ‘string’. and whether or not it is sortedWhen things are put into order, eg from largest to smallest..
The biggest problem with a serial search is that it is very slow. For example, when searching through a database of everyone in the UK to find a particular name, it might be necessary to search through 60 million names before you found the one you wanted.
Binary search
One of the main advantages of a binary searchA method of searching in which the data being searched is halved with every step. is that it is much quicker than a serial search because the data that needs to be searched halves with each step. For example, it is possible to search through 1024 values and find the one you want within 10 steps, every time.
The biggest problem with a binary search is that you can only use this if the data is sorted into an order.