logo Hurry, Grab up to 30% discount on the entire course
Order Now logo
570 Times Downloaded

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Rasmi SehgalSocial sciences
(5/5)

516 Answers

Hire Me
expert
Charlie BilyeuBusiness
(4/5)

581 Answers

Hire Me
expert
Tanusree KunduMathematics
(/5)

778 Answers

Hire Me
expert
Richardd RussellHistory
(4/5)

760 Answers

Hire Me
Others
(5/5)

Create a Python program called SearchComparisons.py that asks if a generated list is to be printed.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Search Comparisons:   Create a Python program called SearchComparisons.py that asks if a generated list is to be printed.  The user enters “y” to print the list, or “n” to not. Anything else will end the program with an “Invalid response” message). The program then asks for the length of the list to be created. An array of randomly generated integers is then created as well as a random integer key.  Both are determined by the list length.  For example, a list length of 7 will generate 7 random integers and a random key all between 0 and 6.   The program does a linear search on the key and reports its position (first occurrence).  Then, the program sorts the list in ascending order for a binary search on the key. The binary search captures the number of reads to find the key.  All user-defined functions should be completely written by the student without the use of utilities in Python built-in modules.  See the sample output, user-defined headers and flowcharts below.  When complete, please rename your program to “Your name Lab07A.py” and send it to me as an attachment in a Blackboard message.  User-defined function headers are:

  linearSearch(listIn, key)    

  bubbleSort(listIn)  

  binarySearch(listIn, key)

 

Sample runs:

Enter 'y' to print the list, 'n' to not print the list: y

Enter list length: 9

Key = 6

Unsorted list: [6, 7, 5, 1, 3, 6, 1, 4, 7]

Key 6 found in linear search at position: 1

Sorted list: [1, 1, 3, 4, 5, 6, 6, 7, 7]

Key 6 found in binary search after 2 reads.

 

Enter 'y' to print the list, 'n' to not print the list: y

Enter list length: 7

Key = 2

Unsorted list: [0, 0, 5, 3, 1, 4, 1]

No key found in linear search

Sorted list: [0, 0, 1, 1, 3, 4, 5]

No key found in binary search

 

Enter 'y' to print the list, 'n' to not print the list: n

Enter list length: 1000

Key = 116

No key found in linear search

No key found in binary search

 

Enter 'y' to print the list, 'n' to not print the list: n

Enter list length: 10000

Key = 7252

Key 7252 found in linear search at position: 7563

Key 7252 found in binary search after 12 reads.

 

(5/5)
Attachments:

Expert's Answer

570 Times Downloaded

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme