Consider the pseudocode for insertion sort. Here, the next element in the unsorted portion of the list is swapped to the left until we find its appropriate location in the sorted part of the list. Describe another approach for determining where the next element belongs in the sorted portion of the list. In the context of sorting a vector in C++, does this affect the overall asymptotic run time of insertion sort? Why or why not?
Consider the pseudocode for insertion sort.
Here, the next element in the unsorted portion of the list is swapped to the left until we find its appropriate location in the sorted part of the list. Describe another approach for determining where the next element belongs in the sorted portion of the list. In the context of sorting a
Insertion Sort:
Insertion sort iterates through the input list, eating one element each time, and producing a sorted output list.
Insertion sort takes one element first from input data at a time, finds where it belongs inside the sorted list, & inserts it there.
It keeps going until there are no more input elements.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images