|
| 1 | +<name> |
| 2 | +<date> |
| 3 | + |
| 4 | +1. Write code to swap the values 25 and 40. |
| 5 | + |
| 6 | +my_list = [55, 41, 52, 68, 45, 27, 40, 25, 37, 26] |
| 7 | + |
| 8 | +2. Write code to swap the values 2 and 27. |
| 9 | + |
| 10 | +my_list = [27, 32, 18, 2, 11, 57, 14, 38, 19, 91] |
| 11 | + |
| 12 | +3. Why does the following code not work? Explain it, don't just list working code. |
| 13 | + |
| 14 | +my_list = [70, 32, 98, 88, 92, 36, 81, 83, 87, 66] |
| 15 | +temp = my_list[0] |
| 16 | +my_list[1] = my_list[0] |
| 17 | +my_list[0] = temp |
| 18 | + |
| 19 | +4. Show how the following numbers can be sorted using the selection sort. Show |
| 20 | +the numbers after each iteration of the outer loop, similar to what is shown in |
| 21 | +the book. I am NOT looking for a copy of the code to do the sort. If you include |
| 22 | +any code for problems 4-7 you are doing it wrong. |
| 23 | + |
| 24 | +97 74 8 22 47 92 18 11 0 60 |
| 25 | + |
| 26 | +5. Show how the following numbers can be sorted using the selection sort: |
| 27 | + |
| 28 | +73 92 28 47 30 58 0 36 31 25 |
| 29 | + |
| 30 | +6. Show how the following numbers can be sorted using the INSERTION sort. |
| 31 | +(Note: If you think the 0 gets immediately sorted into position, you are doing |
| 32 | +it wrong. Go back and re-read how this sort works.) |
| 33 | + |
| 34 | +97 74 8 22 47 92 18 11 0 60 |
| 35 | + |
| 36 | +7. Show how the following numbers can be sorted using the insertion sort: |
| 37 | + |
| 38 | +73 92 28 47 30 58 0 36 31 25 |
| 39 | + |
| 40 | +8. Explain what `min_pos` does in the selection sort. |
| 41 | + |
| 42 | +9. Explain what `cur_pos` does in the selection sort. |
| 43 | + |
| 44 | +10. Explain what `scan_pos` does in the selection sort. |
| 45 | + |
| 46 | +11. Explain what `key_pos` and `key_value` are in the insertion sort. |
| 47 | + |
| 48 | +12. Explain `scan_pos` in the insertion sort. |
| 49 | + |
| 50 | +13. Look at the example sort program at the very end of this chapter: |
| 51 | + |
| 52 | +https://learn.arcade.academy/en/latest/chapters/30_sorting/sorting.html |
| 53 | + |
| 54 | +Modify the sorts to print the number of times the inside loop is run, and the |
| 55 | +number of times the outside loop is run. Modify the program to work with a list |
| 56 | +of 100. Paste the code you used here. Run the program and list the numbers you |
| 57 | +got here. (DON'T FORGET TO INCLUDE THE RESULTS!) Inside loop for selection sort |
| 58 | +should be about 5,000, and insertion sort 2,500. Double-check if you don't get |
| 59 | +numbers close to these. |
0 commit comments