Home / Expert Answers / Computer Science / nbsp-help-me-here-please-i-am-struggling-for-parts-c-and-d-1-a-write-python-code-for-a-rec-pa608

(Solved):   Help me here please!! I am struggling for parts c and d 1) a) Write python code for a rec ...



1) a) Write python code for a recursive algorithm that will calculate the number of digits in the binary expansion/representa

 

Help me here please!! I am struggling for parts c and d

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 \( \mathrm{n} \). The logic of the recursive algorithm should be something like: if \( \mathrm{n}=1 \), the answer is 1 ; if \( \mathrm{n}>1 \), the answer is 1 more than the number of digits in the binary representation of \( \mathrm{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 \( \mathrm{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 \( \mathrm{n} \). It is not creating the binary expansion of \( \mathrm{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 \( \mathrm{n}=32 \) and \( \mathrm{n}=75 \). 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 \( \mathrm{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.


We have an Answer from Expert

View Expert Answer

Expert Answer


Solution: c) Number n is passed to the function inside the function
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe