Top MCQs on InsertionSort Algorithm with Answers

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 n-1 … More on Insertion Sort
Insertion Sort

Insertion Sort

 
Question 1

Which of the following is not a stable sorting algorithm in its typical implementation.

Cross

Insertion Sort

Cross

Merge Sort

Tick

Quick Sort

Cross

Bubble Sort



Question 1-Explanation: 

Quick Sort is not a stable sorting algorithm in its typical implementation.

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).

Cross

Quick Sort

Cross

Heap Sort

Cross

Merge Sort

Tick

Insertion Sort



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 linear time in their typical implementation.

Question 3

What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?

Cross

N

Cross

N*log(N)

Tick

N2

Cross

N*log(N)2



Question 3-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 the insertion of 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.
  3. Using binary search reduces the time complexity in step #1 from O(N) to O(log(N)). But, the time complexity in step #2 still remains O(N).

 So, overall complexity remains O(N2).

Question 4

Which sorting algorithm will take least time when all elements of input array are identical? Consider typical implementations of sorting algorithms.

Tick

Insertion Sort

Cross

Heap Sort

Cross

Merge Sort

Cross

Selection Sort



Question 4-Explanation: 

The insertion sort will O(n) time when input array is already sorted.

Question 5

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?

Cross

Θ (n2)

Cross

Θ (n*log(n))

Cross

Θ (n1.5)

Tick

Θ (n)



Question 5-Explanation: 

Insertion sort runs in Θ(n + f(n)) time, where f(n) denotes the number of inversions initially present in the array being sorted.
Source: http://cs.xidian.edu.cn/jpkc/Algorithm/down/Solution%20to%202-4%20Inversions.pdf

Question 6

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.  

Tick

4 5 3 2 1

3 4 5 2 1

2 3 4 5 1

1 2 3 4 5

Cross

5 4 3 1 2

5 4 1 2 3

5 1 2 3 4

1 2 3 4 5

Cross

4 3 2 1 5

3 2 1 5 4

2 1 5 4 3

1 5 4 3 2

Cross

4 5 3 2 1

2 3 4 5 1

3 4 5 2 1

1 2 3 4 5



Question 6-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 7
Which is the correct order of the following algorithms with respect to their time Complexity in the best case ?
Cross
Merge sort > Quick sort >Insertion sort > selection sort
Tick
insertion sort < Quick sort < Merge sort < selection sort
Cross
Merge sort > selection sort > quick sort > insertion sort
Cross
Merge sort > Quick sort > selection sort > insertion sort


Question 7-Explanation: 
In best case, 

Quick sort: O (nlogn) 
Merge sort: O (nlogn)
Insertion sort: O (n)
Selection sort: O (n^2)  
Question 8
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. 
Tick
Insertion sort is stable, online but not suited well for large number of elements.
Cross
Insertion sort is unstable and online
Cross
Insertion sort is online and can be applied to more than 100 elements
Cross
Insertion sort is stable & online and can be applied to more than 100 elements


Question 8-Explanation: 
Time taken by algorithm is good for small number of elements, but increases quadratically for large number of elements.
Question 9
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  ?
Tick
50
Cross
25
Cross
75
Cross
100


Question 9-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.
Question 10

The auxiliary space of insertion sort is O(1), what does O(1) mean?

Cross

The memory (space) required to process the data is not constant.

Tick

It means the amount of extra memory Insertion Sort consumes doesn't depend on the input. The algorithm should use the same amount of memory for all inputs.

Cross

It takes only 1 kb of memory.

Cross

It is the speed at which the elements are traversed.



Question 10-Explanation: 

The term O(1) states that the space required by the insertion sort is constant i.e., the space required doesn't depend on input.

There are 13 questions to complete.
 

Coding practice for sorting.

 

  • Last Updated : 27 Sep, 2023

Share your thoughts in the comments
Similar Reads