Searching and sorting algorithms Flashcards
Linear search
The most simple search algorithm
Each data item is searches in order from the first value to the last. Also works when data is not in order
For large lists, this search is not very efficient
Binary search
Generally searches through fewer data and is often much quicker, especially for larger data sets
The middle point of the data is selected with each iteration and compared to the value being searches for. Search stops when midpoint matches target value
Data must already be sorted
The upper half or lower half of the data is ignored if the midpoint does not equal the target
Merge sort
Divides a list into half and again and again until each data item is separate. Then, the items are combined in the same way as they were divided, but now in the correct order. The algorithm then ends
Bubble sort
Data elements are swapped if they are not in the correct order
The algorithm will only stop when a complete iteration is completed with no swaps made
Not suitable for large sets of data
Insertion sort
Less complex and efficient than merge sort, but more efficient than bubble sort
Compares values in turn, starting with the second value in the list. If this value is greater than the value to the left of it, no changes are made. Otherwise this value is repeatedly moved left until it meets a value that is less than it. Then starts again with the next value and so on