Submit your code as a zipped file with your code (two .py files) and iour outputs...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Submit your code as a zipped file with your code (two .py files) and iour outputs (a .pdf file) Topics: Coding a recursive function; recurrence relation; back substitution or master method 1) a) Write python code for a recursive algorithm that will calculate the number of digits in the binary expansion/representation of a positive integer n. The logic of the recursive algorithm should be something like: if n 1, the answer is 1; if n> 1, the answer is 1 more than the number of digits in the binary representation of n/2. You might want to use the python function math.floor() in your code. Your function should have only one input parameter - a positive integer n. It should return the number of digits using a return statement. There should be no print statements in the function. Note: Your function is determining the number of digits in the binary expansion of n. It is not creating the binary expansion of n. Be sure to include comments identifying the input and output for this algorithm, as well as comments explaining what is accomplished by the key steps of the algorithm. b) Run your code on the problem instances n = 256 and n = 750. Show me the output generated by having your main/driver code block call the function inside a print statement. c) Create a recurrence relation that gives the work performed by the algorithm in the worst-case for a problem of size n. In your recurrence relation, count the number of recursive calls to the function as the fundamental unit of work. In your asymptotic analysis, you can assume that n is an integer power of 2. d) Perform the asymptotic analysis with either the back-substitution method OR the master method to solve the recurrence relation and determine the algorithm's asymptotic class Big-Oh. Submit your code as a zipped file with your code (two .py files) and iour outputs (a .pdf file) Topics: Coding a recursive function; recurrence relation; back substitution or master method 1) a) Write python code for a recursive algorithm that will calculate the number of digits in the binary expansion/representation of a positive integer n. The logic of the recursive algorithm should be something like: if n 1, the answer is 1; if n> 1, the answer is 1 more than the number of digits in the binary representation of n/2. You might want to use the python function math.floor() in your code. Your function should have only one input parameter - a positive integer n. It should return the number of digits using a return statement. There should be no print statements in the function. Note: Your function is determining the number of digits in the binary expansion of n. It is not creating the binary expansion of n. Be sure to include comments identifying the input and output for this algorithm, as well as comments explaining what is accomplished by the key steps of the algorithm. b) Run your code on the problem instances n = 256 and n = 750. Show me the output generated by having your main/driver code block call the function inside a print statement. c) Create a recurrence relation that gives the work performed by the algorithm in the worst-case for a problem of size n. In your recurrence relation, count the number of recursive calls to the function as the fundamental unit of work. In your asymptotic analysis, you can assume that n is an integer power of 2. d) Perform the asymptotic analysis with either the back-substitution method OR the master method to solve the recurrence relation and determine the algorithm's asymptotic class Big-Oh.
Expert Answer:
Answer rating: 100% (QA)
Lets go through each part of the question step by step a Recursive Function to Calculate Binary Digi... View the full answer
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
For the following two graphics, provide the specified information below for each. Inverse Demand: P= 43.75 - .00625 Q; MR = 43.75 - 0.0125 Q 25 20 15 $ per unit 10 10 5 0 MC 500 1000 1500 ATC 2000 -...
-
This exercise is meant to help you to understand how to use functions in Python. In this week's exercise, you are asked to create a simple tool that converts temperatures from one temperature type to...
-
H. Brown (Portsmouth) Ltd produces a range of central heating systems for sale to builders merchants. As a result of increasing demand for the businesss products, the directors have decided to expand...
-
Continuing the previous problem, operators have made an adjustment that they hope will improve the functioning of this process. The file P20_04.xlsx contains 25 subsamples of 6 observations each on...
-
On July 1, 2020, Academic Learning Services entered its second month of operations. On July 31, 2020, Breanne Allarie, the owner, finalized the company?s records that showed the following items. Use...
-
1. Why was the City of Cedar Park attempting to address the way in which it communicated water consumption information to its customers? 2. Why were City of Cedar Park customers frustrated? 3. What...
-
Valley Company's adjusted trial balance on August 31, 2013, its fiscal year- end, follows. On August 31, 2012, merchandise inventory was $ 25,400. Supplementary records of merchandising activities...
-
List and analyze the selection to demonstrate whether you agree or disagree with the list. Explain why or why not....
-
Alexander Smith and his wife Allison are married and file a joint tax return for 2019. The Smiths live at 1234 Buena Vista Drive, Orlando, FL 32830. Alexander is a commuter airline pilot but took 6...
-
On August 1, Grayson Company bought goods with a list price of $4,800, terms 2/10, n/30. The firm records purchases at invoice price using the perpetual inventory system. On August 5 Grayson returned...
-
implement the RecursiveCrawler class in Java . import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import java.io.*; import java.util.*; public class...
-
Using the values provided in the amortization table,find the beginning pool balance in the second year of the loan. Express your answer as a number rounded to two decimal points (e.g. is your answer...
-
Add player class to the project. - Add public data: int numPlayers - Instantiate in main and test. Add a print statement Add seLinkList class to the project. - This class should be a Single Linked...
-
Question: Buckeye Computer, Inc. produces high performance image generators for simulation (including PC-based visual system products) and visual workstations for high-end graphics applications. Its...
-
Consider the disk drive depicted in Figure 3.11. Disk where Read/write head V Figure 3.11: Disk Drive Problem The horizontal position of the head shown in Figure 3.11 is driven by a motor which may...
-
Suppose we wish to detect a difference of $0.094 (just under a dime) between two different online ads. Suppose the standard deviation of the response (sales) is $103.77 (the standard deviation will...
-
Jax Incorporated reports the following data for its only product. The company had no beginning finished goods inventory and it uses absorption costing. $ 57.30 per unit $ 10.30 per unit $ 7.80 per...
-
Write a method firstFive that accepts a file name string as its parameter and uses stream operations to print the first five non-blank lines of the file. Do not use any loops or collections; perform...
-
What is the output of the following oddStuff method? public static void oddStuff() { int number 4; for (int count 1; count
-
Write a method called readEntireFile that accepts a Scanner representing an input file as its parameter, then reads that file and returns its entire text contents as a String.
-
Solve Chapter Problem 13.21, assuming the power spectral density is band limited with \(\omega_{1}=50 \mathrm{rad} / \mathrm{s}\) and \(\omega_{2}=200 \mathrm{rad} / \mathrm{s}\). Data From Chapter...
-
Solve Chapter Problem 13.21, assuming the force is narrowband with a power spectral density given by \(S_{F}(\omega)=\frac{3 \times 10^{-3}}{2+5 \omega^{2}}\). Data From Chapter Problem 13.21: A SDOF...
-
Fine Leather Ltd has provided the following production and sales information for each pair of its dress shoes. The fixed costs for the period are \($1\) 125 000. Required (a) Calculate the...
Study smarter with the SolutionInn App