Not all algorithmA sequence of logical instructions for carrying out a task. In computing, algorithms are needed to design computer programs. are made equal and it is a computer scientist鈥檚 job to consider the patterns and features that would find the best solutions to problems.
For example, sorting data into alphabetical order could be completed using a number of different methods. The programmer could choose to use bubble sortA sorting algorithm that repeatedly passes through a list to be sorted, comparing and swapping items that are in the wrong order. or merge sortA sorting algorithm that repeatedly divides a list in half until each has only one item. The individual lists are then merged. , which are both standard sorting algorithms - but before choosing, it would be important to know which would be most efficient. You can read more about sorting algorithms in the guide.
Efficiency looks at how much time it takes to run a particular algorithm and how much space is needed. By using both measurements, an algorithm that looks much more complex can actually be more efficient.
In the example of sorting data, the programmer might choose to look for the smallest piece of data and put that at the start of a new arrayA set of data values of the same type, stored in a sequence in a computer program. Also known as a list. , then repeat the process until all the data has been removed from the original array. This would certainly solve the problem, but there are better ways to reach the goal. These would be described as being more efficient.