Spec 2.1 ยท Algorithms
Algorithm Arena
Be the computer! Step through searching and sorting one decision at a time.
Score 0
Mistakes 0
Best 0
How the algorithms work
- Linear search โ check each item in turn from the start until the target is found or the list ends. Works on unsorted data.
- Binary search โ the list must be sorted. Check the middle item (mid = (low + high) DIV 2). If it is the target, stop. If the target is bigger, discard the left half; if smaller, discard the right half. Repeat.
- Bubble sort โ compare each adjacent pair and swap if they're in the wrong order. After each pass the largest unsorted item has "bubbled" to the end. Stop when a pass makes no swaps.
- Insertion sort โ take each item in turn and insert it into the correct position in the sorted part on the left.
- Merge sort โ split the list in half repeatedly until every list has one item, then merge pairs of lists back together in order by repeatedly taking the smaller front item.