Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1for i in range(len(nums)): | ASwaps the item at position i with the smallest item found at position m. | |
| 2nums[i], nums[m] = nums[m], nums[i] | BThe outer loop: it goes through each position in the list, one at a time, to fill with the smallest remaining item. | |
| 3The inner loop searches the unsorted part of the list to find the position of the smallest item. | CThis is a bad swap. The first line overwrites nums[i], so its original value is lost and both items end up the same. | |
| 4When the inner loop finds a smaller item, remember its position as the new minimum. | Dif nums[j] < nums[m]: m = j | |
| 5nums[i] = nums[m] nums[m] = nums[i] | EThe inner loop always sets m to j without comparing, so m just ends up as the last position instead of the smallest item. | |
| 6for j in range(i, len(nums)): m = j | Ffor j in range(i + 1, len(nums)): |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
selection sort — A sorting algorithm that uses nested loops to find the smallest remaining item, then swaps it into place with a, b = b, a. It repeats for each position until the list is sorted.for i in range(len(nums)):
smallest = ifor j in range(i + 1, len(nums)):if nums[j] < nums[smallest]:
smallest = ja[i], a[m] = a[m], a[i]for i in range(len(nums)):
smallest = i
for j in range(i + 1, len(nums)):