Q.Consider a list of 10 elements: randList = [7,11,3,10,17,23,1,4,21,5]. Determine the partially sorted list after four complete passes of selection sort.
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →This problem requires tracing the Selection Sort algorithm for four complete passes on the given list randList = [7,11,3,10,17,23,1,4,21,5] to determine its state.
Selection Sort is an in-place comparison sorting algorithm. It works by repeatedly finding the minimum element from the unsorted part of the list and putting it at the beginning of the unsorted part.
The core idea is to divide the list into two parts: a sorted sublist and an unsorted sublist. Initially, the sorted sublist is empty, and the unsorted sublist is the entire list.
How Selection Sort Works (One Pass):
In each "pass" (or iteration), the algorithm performs the following steps:
- It finds the smallest element in the unsorted sublist.
- It swaps this smallest element with the first element of the unsorted sublist.
- This effectively moves the smallest element to its correct position in the sorted sublist, and the boundary between the sorted and unsorted sublists shifts one position to the right.
For a list of elements, Selection Sort requires passes to fully sort the list. After passes, the first elements of the list will be sorted and in their final positions.
Let's trace the given list randList = [7, 11, 3, 10, 17, 23, 1, 4, 21, 5] through four complete passes.
| Pass | Current List State | Unsorted Sublist (highlighted) | Minimum Element Found | Index of Minimum | Element at Current Sorted Position | Swap Action | List After Pass |
|---|---|---|---|---|---|---|---|
| Initial | [7, 11, 3, 10, 17, 23, 1, 4, 21, 5] | [7, 11, 3, 10, 17, 23, 1, 4, 21, 5] | - | - | - | - | [7, 11, 3, 10, 17, 23, 1, 4, 21, 5] |
| 1 | [7, 11, 3, 10, 17, 23, 1, 4, 21, 5] | [**7**, 11, 3, 10, 17, 23, 1, 4, 21, 5] | 1 | 6 | 7 (at index 0) | Swap randList[0] (7) with randList[6] (1) | [1, 11, 3, 10, 17, 23, 7, 4, 21, 5] |
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.