40 questions · timed · auto-graded
For example:If the list CITIES contains[“AHMEDABAD”,”CHENNAI”,”NEW DELHI”,”AMRITSAR”,”AGRA”]The following should get displayedAHEMDABADAMRITSARAGRA
( i.e: student_name, roll_number, avg_marks )
Selection sort:

Write the complete steps to sort the above along with each pass explanation.

Iteration 1 : Select the smallest element from unsorted array which is 3 and exchange 3 with the first element of the unsorted array i.e. exchange 3 with 8. After 1st iteration the element 3 is at its final position in the array.

Iteration 2: The second pass identifies 4 as the next smallest element and then exchange 4 with 5.

Iteration 3: The third pass identifies 5 as the next smallest element and then exchange 5 with 9.
Iteration 4: The third pass identifies 7 as the next smallest element and then exchange 7 with 8.
Iteration 5: The third pass identifies 8 as the next smallest element and then exchange 8 with 16
Iteration 6: The third pass identifies 9 as the next smallest element and then exchange 9 with 9 which makes no effect. Thus, the final list
Write the complete steps to sort the above along with each pass explanation.
Now, we get the sorted list is as follows:
The above procedure can also be shown as:
Write the complete steps to sort the above along with each pass explanation.
This completes one pass (round) of comparisons. This pass had 6 individual comparisons and had put the most significant element (9) of the list at the last position.
Now, the second pass of the comparisons starts. We shall not include the last element (9) in this pass, as it is the most significant element of the list and has been put at its required position by the previous pass. The second pass goes as follows:
This completes the second pass of comparisons. This pass had 5 individual comparisons and has put the most significant element (8), of the list of first six elements, at the last position. It gives the following list:
So, now we have one less element to sort.
It means that in each pass we are taking one element to its required position in the sorted list. This is repeated until all the elements have been sorted. Let us see the list after each pass:
We observe that each pass takes one element to its desired position, and hence, six elements are at their desired positions in six passes, and the seventh element is automatically left at its desired position. So, a list of seven elements are sorted in six passes.
In general, a list of N elements can be sorted in N-1 passes.