Skip to content
Related Articles

Related Articles

Improve Article
GATE | Quiz for Sudo GATE 2021 | Question 17
  • Last Updated : 15 Dec, 2020

Consider the following list of the integer:

19, 23, 40, 32, 91, 25, 100, 36 

Sort this list in increasing order using insertion sort and determine the number of passes, comparisons, and swaps. Here a pass means iteration of main loop. We may assume that we start checking from first element which is 19 here.

Note – This question is multiple select questions (MSQ).
(A) There will be total 8 passes for all 8 integers
(B) Number of comparisons and Swaps for each pass for given sequences to sort in increasing order are 14 and 7 respectively
(C) Number of comparisons for each pass for given sequences to sort in increasing order is 7
(D) Number of swaps for each pass for given sequences to sort in increasing order is 14


Answer: (A) (B)

Explanation: According to Insertion Sort, there will be total 8 passes for all 8 integers. Number of comparisons and Swaps for each pass for given sequences to sort in increasing order:

Comparisons: 0, 1, 1, 2, 1, 4, 1, 4 = 14 
Swaps: 0, 0, 0, 1, 0, 3, 0, 3 = 7 

So, options (A) and (B) are correct.

Quiz of this Question
Please comment below if you find anything wrong in the above post

Attention reader! Don’t stop learning now. Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :