\
  InsertionSort(A[],n)
    1.   For i = 1 to n
    2.     Key<-Arr[i]
    3.     j<-[i-1]
    4.     while(j>0 and Arr[j]>Key)
    5.         A[j+1]<-A[j]
    6.         j<-j-1
    7.     A[j+1]<-Key
|
|
Space | ||
| Best Case | Average Case | Worst Case | |
What is the working mechanism of Insertion Sort, and what is
the origin of its name?
Insertion sort is a simple sorting algorithm that works
similar to the way you sort playing cards in your hands.
The array is virtually split into a sorted and an unsorted part.
Values from the unsorted part are picked and placed at the correct
position in the sorted part.
Is insertion sort a stable,
in-place sorting algorithm or an out-of-place sorting algorithm?
Insertion sort is a stable in-place algorithm, meaning that it does not require any extra space and maintains the relative order of duplicates.
How does the number of elements impact the efficiency of insertion sort?
The efficiency of insertion sort is impacted by the size of the input list, and as the list size increases,
the number of iterations needed for the algorithm to sort the list also increases, which can result in poor
performance when sorting large lists, making it unsuitable for large-scale applications.
What are advantages and disadvantages of insertion Sort?
Advantages: