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 x2nx\ne2^n for positive innnteger nn. So, more extended:

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

for any arbitrary positive integer nn.

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!
LATEST TUTORIALS
APPROVED BY CLIENTS