![]() |
VOOZH | about |
Recursive Insertion Sort is a variation of the standard Insertion Sort algorithm that uses recursion instead of iterative loops. It sorts an array by recursively sorting smaller portions of the array and inserting each element into its correct position in the sorted part.
Treat the first n-1 elements as a smaller subproblem - sort them recursively - and then insert the nth element into the correct position among them. This process continues until the array is fully sorted. Below is the step-by-step guide:
[-7, -3, 0, 2, 5, 6, 10, 11]
Explanation:
while loop shifts elements greater than last to the right.arr[j + 1] = last inserts last in its correct position.