English

Consider the following lists: List 1: 2 3 5 7 11 List 2: 11 7 5 3 2 If the lists are sorted using Insertion sort then which of the lists List1 or List 2 will make the minimum number of comparisons? - Computer Science (Python)

Advertisements
Advertisements

Question

Consider the following lists:

List 1:

2 3 5 7 11

List 2: 

11 7 5 3 2

If the lists are sorted using Insertion sort then which of the lists List1 or List 2 will make the minimum number of comparisons? Justify using diagrammatic representation.

Answer in Brief

Solution

In case of sorting in Ascending order, List 1 will make minimum number of comparisons as it is already in ascending order.

In case of Descending order, List 2 will make minimum number of comparisons as it is in descending order.

Following diagram shows comparisons for ascending order sorting:

shaalaa.com
Insertion Sort
  Is there an error in this question or solution?
Chapter 5: Sorting - Exercise [Page 79]

APPEARS IN

NCERT Computer Science [English] Class 12
Chapter 5 Sorting
Exercise | Q 3. | Page 79
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×