Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make a class with a favorite hobby and have a description of the hobby and an ID (as an integer. Please store numbers in this

Make a class with a favorite hobby and have a description of the hobby and an ID (as an integer. Please store numbers in this data for the class and if you get numbers input from the user make sure to cast them to integer before you store them. Searches work better comparing numbers.) It should have an ID, one other stored variable, and you only need to code the __init__ constructor. Make 3 different objects of your class and store them in a list. Write a binary and a linear search. Ask the user for an ID and tell the user if its in the List or not.

Part 2

Make 3 variables at the start of the program to count how many times something happens. The first will count comparisons in the Linear Search, the second comparisons a simple sort you are going to write, and the last comparisons in the Binary Search. Set all three to 0. Change the ID values in your 3 objects of your class so they are mixed up and not in order by ID at the beginning of your program. Write a simple bubble sort to sort your List by ID before the Binary Search so it will still work. Add one to the counter for the linear search right before the IF checking to see if it finds an ID (not inside the IF, before it. You are counting how many times it has to check not the one time it may find something.) Add one to the counter for the Binary search right before the IF checking to see if it finds an ID (not inside the IF, before it. You are counting how many times it has to check not the one time it may find something.) Add one to the counter for the Bubble Sort right before the IF checking to see if it needs to swap two objects. Print out all three values to the user telling them the number of operations the linear search, binary search, and sort for the binary search used.

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

13th edition

1439078106, 111197375X, 9781439078105, 9781111973759, 978-1439078099

More Books

Students also viewed these Finance questions