Question: Implement a recursive version of insertion sort. Remember its definition from the lectures. Insertion sort is a simple sorting algorithm that works similarly to the
Implement a recursive version of insertion sort. Remember its definition from the lectures.
Insertion sort is a simple sorting algorithm that works similarly to the way you sort playing cards
in your hands. The list is virtually split into a sorted and an unsorted part. Values from the unsorted
part are picked and placed in the correct position in the sorted part. To sort a list of size n in
ascending order:
: Iterate from arr to arrn over the list.
: Compare the current element key to its predecessor.
: If the key element is smaller than its predecessor, compare it to the elements before. Move the
greater elements one position up to make space for the swapped element.
Recursion idea:
: Base Case: If list size is or smaller, return.
: Recursively sort first n elements.
: Insert last element at its correct position in sorted list.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
