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.
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:
APPEARS IN
RELATED QUESTIONS
______ is putting an element in the appropriate place in a sorted list yields a larger sorted order list.
What will be the number of passes needed to sort a list of five elements?
Arranging a pack of cards is an example of:
In insertion sort average number of comparisons required to place the 7th element into the correct position is:
How would [34, 8, 64, 51, 32, 21] look like after second pass of insertion sort?
What would be the running time of an insertion sort for a pre-sorted list?
Which algorithm is similar to placing cards at the right position while playing cards?
During admission in a course, the names of the students are inserted in ascending order. Thus, performing the sorting operation at the time of inserting elements in a list. Identify the type of sorting technique being used and write a program using a user defined function that is invoked every time a name is input and stores the name in ascending order of names in the list.