Binary Search
Binary search is an O(log n) algorithm that is used to find a value in a sorted
list of items. It works by searching for a
value in the middle of a list,
and recursively discarding whichever half of the list is out of range. The result
of a binary search is undetermined if the list is unsorted.
Binary search
is available in the Arrays and Collections classes.
Insertion Sort
Insertion sort is an O(n^2) average-case sorting algorithm. It works
by traversing through a list and sorting the previous
elements by swapping them
in place. Insertion sort is a stable algorithm, which
means equal values will
maintain their relative order. Insertion sort performs well for small data sets
despite its complexity because it’s efficient for
partially sorted lists and
it requires no extra memory.