Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The selection sort algorithm is def selectionSort(aList): for fillslot in range(len(aList)-1,0,-1): positionOfMax=0 for location in range(1,fillslot+1): if aList[location]>aList[positionOfMax]: positionOfMax = location # swap largest element
The selection sort algorithm is
def selectionSort(aList): for fillslot in range(len(aList)-1,0,-1): positionOfMax=0 for location in range(1,fillslot+1): if aList[location]>aList[positionOfMax]: positionOfMax = location # swap largest element in correct place temp = aList[fillslot] aList[fillslot] = aList[positionOfMax] aList[positionOfMax] = tempQ3 Selection Sort 20 Points The textbook goes through the implementation of the Selection Sort algorithm. Use the implementation in the textbook to answer the following subquestions. Q3.1 10 Points Assume we pass the following list into the Selection Sort function: [1, 10, 3, 7, 9, 5] Write the state of the list (as if it were in a print function) at the end of the iteration where fillslot = 4. I would try and work through this algorithm by hand first. You can always double-check your answer by writing this algorithm and running it. Note that this question will be autograded, so please be EXACT with your answer (same spacing, brackets, commas, etc) as you would see in printing a list to the interactive shell (such as [X, Y, Z]). Enter your answer here Save Answer Q3.2 10 Points Assume we pass the following list into the Selection Sort function: [1, 10, 3, 7, 9, 5] Write the state of the list (as if it were in a print function) at the end of the iteration where fillslot = 2 I would try and work through this algorithm by hand first. You can always double-check your answer by writing this algorithm and running it. Note that this question will be autograded, so please be EXACT with your answer (same spacing, brackets, commas, etc) as you would see in printing a list to the interactive shell (such as [X, Y, z]). Enter your answer here
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started