An algorithm could be used to map out different types of road routes
An algorithm is a set of instructions to solve a problem or complete a task. Algorithms are vital for programming, as they provide a computer with the instructions to perform a specific task.
There are some simple algorithms that perform common tasks, such as searching and sorting items in a list. Whereas a complex algorithm may look at more complicated issues, such as road networks. The algorithm could be used to map out routes, for example, the shortest, fastest and longest journeys.
Types of simple algorithms
Linear search
A linear search checks each item in a list one by one until it finds the item it is looking for or reaches the end of the list. An example might be looking for a book from left to right on a library shelf until you find the one you are looking for.
Binary search
The binary search only works on sorted lists. It checks the middle item in the list. As the list is in order, the algorithm can decide if the value is before or after the mid point. The list is then halved, to include the possible value it is searching for. This repeats until the target is found or is not found in the list. For example, when using a dictionary, you don’t check every page, you flip to the middle and decide whether to look left or right, based on its position in the alphabet.
Bubble sort
A bubble sort compares pairs of items and swaps them if they are in the wrong order. This is repeated until the list is sorted. An example would be sorting the highest points for a sports team to the top of the list until you see each team’s position in the league.
Merge sort
A merge sort splits the items in a list until each list contains one value. It then merges pairs of sub-lists and sorts the smaller lists in order until each of the sub-lists have been merged together into a final sorted list.