Answer to Question #92389 in Python for AKHILA

Question #92389
What does h(3231) return for the following function definition?

def h(x):
(m,a) = (1,0)
while m <= x:
(m,a) = (m*2,a+1)
return(a)
1
Expert's answer
2019-08-13T06:32:05-0400

Sure. I did mention "x\\ne2^n" for positive innnteger "n". So, more extended:

"h(x)=\\begin{cases}\n \\lfloor\\log_2 x\\rfloor &\\text{if } x\\ne2^n \\\\\n (log_2 x)+1 &\\text{if } x=2^n\n\\end{cases}"

for any arbitrary positive integer "n".

It can be seen inserting print(m) in the while loop.

So the answer is 12,


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS