come up with a program that employs binary search to report back if a key has...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
come up with a program that employs binary search to report back if a key has been found in a sequence of numbers #INPUT: take in a single integer key value, and a sequence of non negative data terminated by a -1. Assume the data will be given in sorted order. Example: 2, 8, 10, 22, 45, 100. Remember the terminating value of -1 does NOT count as data. #OUTPUT: if the key is found, output a message and the location (index) where it was found. If the key is not found, report back that your program failed to find it. #A skeleton code is given below, please note that the binary_search function is still NOT complete. #Finish defining the binary search function def binary_search(val, key, low, high): #what are the base cases? mid = int((low + high)/2) if(key == val[mid]): return mid if(key > val[mid]): binary search(val, key, mid+1, high) if(key < val[mid]): binary_search(val, key, low, mid-1) #Write the main calling routine below come up with a program that employs binary search to report back if a key has been found in a sequence of numbers #INPUT: take in a single integer key value, and a sequence of non negative data terminated by a -1. Assume the data will be given in sorted order. Example: 2, 8, 10, 22, 45, 100. Remember the terminating value of -1 does NOT count as data. #OUTPUT: if the key is found, output a message and the location (index) where it was found. If the key is not found, report back that your program failed to find it. #A skeleton code is given below, please note that the binary_search function is still NOT complete. #Finish defining the binary search function def binary_search(val, key, low, high): #what are the base cases? mid = int((low + high)/2) if(key == val[mid]): return mid if(key > val[mid]): binary search(val, key, mid+1, high) if(key < val[mid]): binary_search(val, key, low, mid-1) #Write the main calling routine below
Expert Answer:
Answer rating: 100% (QA)
def binarysearchval key low high Base case 1 Key not found if low high ret... View the full answer
Related Book For
Principles Of Information Security
ISBN: 9780357506431
7th Edition
Authors: Michael E. Whitman, Herbert J. Mattord
Posted Date:
Students also viewed these programming questions
-
You are buying a home that costs $225,000. You can choose to obtain a 15-year mortgage or a 30-year mortgage. Assume the interest rate is 5% for both types of mortgages. a) What will be the monthly...
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
Do some amendment and enhance the given research paper: Table of Content Abstract..3 Action Research.4 Research Methodology and Design...5 Literature Review: NoSQL Database7 Proposal.7 Iteration 1..8...
-
Suppose that the weight of a typical American male follows a normal distribution with = 180 lb and = 30 lb. Also, suppose 91.92% of all American males weigh more than I weigh. a. What fraction of...
-
The panel shown forms the end of a trough which is filled with water r to the line AA′. Referring to Sec. 9.2, determine the depth of the point of application of the resultant of the...
-
AOB is the sector of a circle, centre O, radius 8 cm. AC is a tangent to the circle at the point A. CBO is a straight-line and the area of sector AOB is 32 cm 2 . Find a. Angle AOB, in radians b. The...
-
Select two of the approach strategies and develop each one into a one-page dialogue between you and a customer.
-
Conglomerate Company purchased Individual Company for $860,000 cash. A schedule of the fair values of Individuals assets and liabilities as of the purchase date follows. 1. Make the journal entry...
-
Peanut Corporallon exchanged land and cash of $6,500 for equipment the land had a book value of $34.000 Accurn - ilue exchange has commerdal substance.\ Required:\ Note: if no of-equired for o...
-
Calculate the following four reliability coefficients using the Pearson product-moment correlation formula, correlate the scores to determine the reliability coefficient (xx). Show your work. 3....
-
Moody Corporation uses a job-order costing system with a plantwide overhead rate based on machine-hours. At the beginning of the year, the company made the following estimates: Machine-hours required...
-
Describe the differences among activity metrics, interaction metrics, and return metrics.
-
What are two compiler switches that help us prevent undefined program behavior?
-
What is A/B testing and how is it used?
-
What are the characteristics of brand fans?
-
What is a social identity?
-
Joseph earns $200 per week and spends his entire income on cheese (which costs $5 per pound) and crackers (which cost $2 per box). Draw Joseph's budget constraint. If the price of cheese increases to...
-
Catalytic hydrogenation of naphthalene over PdC results in rapid addition of 2 moles of H 2 . Propose a structure for this product.
-
Review staff availability and determine if new personnel will need to be contracted for the project in order to meet and exceed project goals.
-
I. Examine and describe how public-key infrastructure (PKI) is an integrated system of software, encryption methodologies, protocols, legal agreements, and third-party services that enables users to...
-
Which of the following is a hybrid cryptosystem that has become the open-source de facto standard for encryption and authentication of e-mail and file storage applications? a. PGP b. S-HTTP c. SSL d....
-
Brown India Limited manufactures office tables. Normal capacity of the factory is 60,000 tables per annum. Following are the cost and inventory details for the year 200506. Required: Carry out the...
-
Usha Corporation Ltd. sought the advice of an investment advisor for deployment of surplus funds of around Rs. 45 lakh in the stock market. The advisor advised to invest in Bhonsle India Ltd. and...
-
Ram Lakhan Company Ltd. produces one unit of product B by using one unit of raw material A. During 200506 A costed the company 4,200. Conversion cost was 850. As on 31st March 2006, being the...
Study smarter with the SolutionInn App