How Insertion Sort Works
Insertion Sort is a simple and efficient algorithm for sorting a small number of elements. It works by iterating through the list, taking one element at a time and inserting it into its correct position in a sorted portion of the array.
- Start with the second element as a key.
- Compare the key with elements before it.
- Shift elements greater than the key to the right.
- Insert the key into its proper position.
- Repeat for all elements in the list.