Question: Submit your code as a zipped file with your code (two .py files) and iour outputs (a .pdf file) Topics: Coding a recursive function;
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.
Step by Step Solution
There are 3 Steps involved in it
Lets go through each part of the question step by step a Recursive Function to Calculate Binary Digi... View full answer
Get step-by-step solutions from verified subject matter experts
