InsertionSort
Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands.
Algorithm
// Sort an arr[] of size n
insertionSort(arr, n)
Loop from i = 1 to n1 … More on Insertion Sort
Question 1 
Which of the following is not a stable sorting algorithm in its typical implementation.
Insertion Sort  
Merge Sort  
Quick Sort  
Bubble Sort 
Discuss it
Question 1 Explanation:
See following for details.
http://www.geeksforgeeks.org/stabilityinsortingalgorithms/
Question 2 
Which of the following sorting algorithms in its typical implementation gives best performance when applied on an array which is sorted or almost sorted (maximum 1 or two elements are misplaced).
Quick Sort  
Heap Sort  
Merge Sort  
Insertion Sort 
Discuss it
Question 2 Explanation:
Insertion sort takes linear time when input array is sorted or almost sorted (maximum 1 or 2 elements are misplaced).
All other sorting algorithms mentioned above will take more than lienear time in their typical implementation.
Question 3 
Consider a situation where swap operation is very costly. Which of the following sorting algorithms should be preferred so that the number of swap operations are minimized in general?
Heap Sort  
Selection Sort  
Insertion Sort  
Merge Sort 
Discuss it
Question 3 Explanation:
Selection sort makes O(n) swaps which is minimum among all sorting algorithms mentioned above.
Question 4 
What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?
N  
NlogN  
N^2  
N(logN)^2 
Discuss it
Question 4 Explanation:
Applying binary search to calculate the position of the data to be inserted doesn't reduce the time complexity of insertion sort. This is because insertion of a data at an appropriate position involves two steps:
1. Calculate the position.
2. Shift the data from the position calculated in step #1 one step right to create a gap where the data will be inserted.
Using binary search reduces the time complexity in step #1 from O(N) to O(logN). But, the time complexity in step #2 still remains O(N). So, overall complexity remains O(N^2).
Question 5 
Which sorting algorithm will take least time when all elements of input array are identical? Consider typical implementations of sorting algorithms.
Insertion Sort  
Heap Sort  
Merge Sort  
Selection Sort 
Discuss it
Question 5 Explanation:
The insertion sort will take (n) time when input array is already sorted.
Question 6 
In a permutation a1.....an of n distinct integers, an inversion is a pair (ai, aj) such that i < j and ai > aj. What would be the worst case time complexity of the Insertion Sort algorithm, if the inputs are restricted to permutations of 1.....n with at most n inversions?
Θ (n^{2})  
Θ (n log n)  
Θ (n^{1.5})  
Θ (n) 
Discuss it
Question 6 Explanation:
Insertion sort runs in Θ(n + f(n)) time, where f(n) denotes the number of inversion initially present in the array being sorted.
Source: http://cs.xidian.edu.cn/jpkc/Algorithm/down/Solution%20to%2024%20Inversions.pdf
Question 7 
Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array.
4 5 3 2 1
3 4 5 2 1
2 3 4 5 1
1 2 3 4 5
 
5 4 3 1 2
5 4 1 2 3
5 1 2 3 4
1 2 3 4 5
 
4 3 2 1 5
3 2 1 5 4
2 1 5 4 3
1 5 4 3 2
 
4 5 3 2 1
2 3 4 5 1
3 4 5 2 1
1 2 3 4 5

Discuss it
Question 7 Explanation:
In the insertion sort , just imagine that the first element is already sorted and all the right side Elements are unsorted, we need to insert all elements one by one from left to right in the sorted Array.
Sorted : 5 unsorted : 4 3 2 1
Insert all elements less than 5 on the left (Considering 5 as the key )
Now key value is 4 and array will look like this
Sorted : 4 5 unsorted : 3 2 1
Similarly for all the cases the key will always be the newly inserted value and all the values will be compared to that key and inserted in to proper position.
Question 8 
Which is the correct order of the following algorithms with respect to their time Complexity in the best case ?
Merge sort > Quick sort >Insertion sort > selection sort  
insertion sort < Quick sort < Merge sort < selection sort  
Merge sort > selection sort > quick sort > insertion sort  
Merge sort > Quick sort > selection sort > insertion sort 
Discuss it
Question 8 Explanation:
In best case, Quick sort: O (nlogn) Merge sort: O (nlogn) Insertion sort: O (n) Selection sort: O (n^2)
Question 9 
Which of the following statements is correct with respect to insertion sort ?
*Online  can sort a list at runtime *Stable  doesn't change the relative order of elements with equal keys.
Insertion sort is stable, online but not suited well for large number of elements.  
Insertion sort is unstable and online  
Insertion sort is online and can be applied to more than 100 elements  
Insertion sort is stable & online and can be applied to more than 100 elements 
Discuss it
Question 9 Explanation:
Time taken by algorithm is good for small number of elements, but increases quadratically for large number of elements.
Question 10 
Consider the array A[]= {6,4,8,1,3} apply the insertion sort to sort the array . Consider the cost associated with each sort is 25 rupees , what is the total cost of the insertion sort when element 1 reaches the first position of the array ?
50  
25  
75  
100 
Discuss it
Question 10 Explanation:
When the element 1 reaches the first position of the array two comparisons are only required hence 25 * 2= 50 rupees.
*step 1: 4 6 8 1 3 .
*step 2: 1 4 6 8 3.
There are 12 questions to complete.
Coding practice for sorting.