Run the code below to define the function # In[ ]: E def minIndexAfter (items, startPos) : minIndex = startPos i = startPos + 1 while (i


Run the code below to define the function<br># In[ ]:<br>E def minIndexAfter (items, startPos) :<br>minIndex = startPos<br>i = startPos + 1<br>while (i < len (items)) :<br>if (items[i] < items[minIndex]):<br>minIndex = i<br>i = i + 1<br>return minIndex<br>Define a function called `selectionSort` below. In the body of the function, you will need to call the `swap<br>function and the `minlndexAfter` function.<br>- Define 'selectionSort' here<br>items = [395,2,-4,20, 47,200,-50,-12]<br>selectionSort (items)<br>print (items)<br>Use the code above to test your 'selectionSort' function<br>

Extracted text: Run the code below to define the function # In[ ]: E def minIndexAfter (items, startPos) : minIndex = startPos i = startPos + 1 while (i < len="" (items))="" :="" if="" (items[i]="">< items[minindex]):="" minindex="i" i="i" +="" 1="" return="" minindex="" define="" a="" function="" called="" `selectionsort`="" below.="" in="" the="" body="" of="" the="" function,="" you="" will="" need="" to="" call="" the="" `swap="" function="" and="" the="" `minlndexafter`="" function.="" -="" define="" 'selectionsort'="" here="" items="[395,2,-4,20," 47,200,-50,-12]="" selectionsort="" (items)="" print="" (items)="" use="" the="" code="" above="" to="" test="" your="" 'selectionsort'="">
Run the code below to call the function<br># In[ ]:<br>otherList = [395,2,-4,20,47,200,-50,-12] #a list for testing<br>print ('Before sorting: ', otherList)<br>bubbleSort (otherList)<br>print ('After sorting:', otherList)<br>a) What are the contents of otherList after a single iteration of the outer loop of 'bubbleSort?<br>b) How many iterations of the outer loop happen when sorting `otherList?<br>* Then run both blocks of code (the def block and the test block) again.<br>* Examine the output to answer the question about iterations.<br>Create a new list below with * elements known as

Extracted text: Run the code below to call the function # In[ ]: otherList = [395,2,-4,20,47,200,-50,-12] #a list for testing print ('Before sorting: ', otherList) bubbleSort (otherList) print ('After sorting:', otherList) a) What are the contents of otherList after a single iteration of the outer loop of 'bubbleSort? b) How many iterations of the outer loop happen when sorting `otherList? * Then run both blocks of code (the def block and the test block) again. * Examine the output to answer the question about iterations. Create a new list below with * elements known as "yourList" - a list where you can get 'bubbleSort` to stop early (do fewer iterations). How many times did the outer loop run for 'yourList? # In[ ]: yourList = [] #fill in this list with 8 elements separated by commas print ('Before sorting:', yourList) bubbleSort (yourList) print ('After sorting:', yourList)

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here