Implement the Insertion Sort algorithm. Build the sorted array one element at a time by inserting each element into its correct position.
For each element from index 1 to n-1, shift larger elements one position right and insert the current element in its correct position.
- Start with index i = 1; treat arr[0..i-1] as sorted.
- Save key = arr[i]; shift elements greater than key one position to the right.
- Place key in the gap created.
- Repeat for all elements. Efficient for nearly-sorted data.
- Time Complexity: O(N^2) worst, O(N) best
- Space Complexity: O(1) in-place