Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What exactly am I supposed to be doing for this? How do I make selection_sort? 1 Problem Compose a program that reads numbers from a

image text in transcribed

What exactly am I supposed to be doing for this? How do I make selection_sort?

1 Problem Compose a program that reads numbers from a fle, uses the function seloctionasort to poet the numbers, and has comments that answer the questions in this assignment. The seloction sort algorithen ixvolves the following invariant 1. The sequence of valucs can be cut into two sub-scoquenes sach that the first sub-sequence is in order and all the preserving the imariant, we find the smallest waloe of the sceond sub-sequenee and move it to the end of the first sub-aequence. Here is an exnmple of seloction sorting. The peeudocode belou suggests how the selection wort algorithm might be implemented. The function find_ain_froe is assumed to return the index of the smallest wlue in the Last for the specificd rayge. procedure selection_sort (1at) for mark in 0 to len (1at)=1 asap(1at, nark, f1ad_ain_free(1at, nark) ) 1.1 Constraints - Uee iteration to implement the algorithm (i.es, use for or uhile loops), - Sort the list of numbers in-place; create no extra lists. - Inplement the specifiod algorithm and wo other. - Do not use any beailt-in Python sont functions. 1. Imeariane! a fuection, quaatity, of property that remains urchanged when a specifed tranefoemation is epplical Ooxiondtangmenes caline. 1 1.2 Program Tasks The solution mast do the following: 1. Prompt for an input file same. The file will coesist of integer values, one per lise. Open the file, read the file, etore the data in a List, and cloee the fike Print the list. Call the aelection, eort function paring the list Reprint the List, which is now sorted. The file must be named selection_sort, py. Devekp and use your own ingut files to test the solution. 1.3 Questions To Answer Nnswer the following questious after implementing the peogram. Write and number answers to the questions in the file docstring that contains your name at the start of the program fle. 1. In what kisd of test case does ingertion_sort perform better than selection_sort? Clearly deseribe the test case. 2. Why does selection sort perform worse than ingertion_aort in that text cab? Copy the inaertion_aort program flle from lecture, and customise the function to mabe it woek with fles. Run the ingertion_sort code with the sime file inputs to compare performance and maner the abowe questions 2 Grading * 40%: Performance Graders will wee a test program that rans tests on the program. Fallare to neme. the fite or the function properily will csuse the test barness to fail, and you will hese points for that. - 25% Sorting code implementation You will get NO credit for aulamiting a non-pelection-4ort implementation - 20% : Fle peoersing and aain code 15% inswers to queations in the tile module docatring Up to 10\%: Deductions off the Top for Style, Layout, Documentation It is expectod that you now know how to write properly documcented Python. The code should follow the couree coding standard on the resources page linked under the course sctedule. Dexiuctions will be for miseing suthor name, missing docstrings for functioes, missing the doestriag for the module itself, and having an incorrect file namo or function name. 2 3 Submission Zip the solution file named selection_sort. pr into a file named honework08. zip, and uplosd the sip file to the myCourses dropbor for this assignment. 1 Problem Compose a program that reads numbers from a fle, uses the function seloctionasort to poet the numbers, and has comments that answer the questions in this assignment. The seloction sort algorithen ixvolves the following invariant 1. The sequence of valucs can be cut into two sub-scoquenes sach that the first sub-sequence is in order and all the preserving the imariant, we find the smallest waloe of the sceond sub-sequenee and move it to the end of the first sub-aequence. Here is an exnmple of seloction sorting. The peeudocode belou suggests how the selection wort algorithm might be implemented. The function find_ain_froe is assumed to return the index of the smallest wlue in the Last for the specificd rayge. procedure selection_sort (1at) for mark in 0 to len (1at)=1 asap(1at, nark, f1ad_ain_free(1at, nark) ) 1.1 Constraints - Uee iteration to implement the algorithm (i.es, use for or uhile loops), - Sort the list of numbers in-place; create no extra lists. - Inplement the specifiod algorithm and wo other. - Do not use any beailt-in Python sont functions. 1. Imeariane! a fuection, quaatity, of property that remains urchanged when a specifed tranefoemation is epplical Ooxiondtangmenes caline. 1 1.2 Program Tasks The solution mast do the following: 1. Prompt for an input file same. The file will coesist of integer values, one per lise. Open the file, read the file, etore the data in a List, and cloee the fike Print the list. Call the aelection, eort function paring the list Reprint the List, which is now sorted. The file must be named selection_sort, py. Devekp and use your own ingut files to test the solution. 1.3 Questions To Answer Nnswer the following questious after implementing the peogram. Write and number answers to the questions in the file docstring that contains your name at the start of the program fle. 1. In what kisd of test case does ingertion_sort perform better than selection_sort? Clearly deseribe the test case. 2. Why does selection sort perform worse than ingertion_aort in that text cab? Copy the inaertion_aort program flle from lecture, and customise the function to mabe it woek with fles. Run the ingertion_sort code with the sime file inputs to compare performance and maner the abowe questions 2 Grading * 40%: Performance Graders will wee a test program that rans tests on the program. Fallare to neme. the fite or the function properily will csuse the test barness to fail, and you will hese points for that. - 25% Sorting code implementation You will get NO credit for aulamiting a non-pelection-4ort implementation - 20% : Fle peoersing and aain code 15% inswers to queations in the tile module docatring Up to 10\%: Deductions off the Top for Style, Layout, Documentation It is expectod that you now know how to write properly documcented Python. The code should follow the couree coding standard on the resources page linked under the course sctedule. Dexiuctions will be for miseing suthor name, missing docstrings for functioes, missing the doestriag for the module itself, and having an incorrect file namo or function name. 2 3 Submission Zip the solution file named selection_sort. pr into a file named honework08. zip, and uplosd the sip file to the myCourses dropbor for this assignment

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

(LO 3-3) How might the data reduction approach be used in auditing?

Answered: 1 week ago