Question

Determine whether each of the following algorithms is fully correct, and prove that your answer is correct.

Determine whether each of the following algorithms is fully correct, and prove that your answer is correct. 4 5 (a) [10 point

0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution:

a. Algorithm is not fully correct.

Algorithm should return the value of log​2

But when the x is not in the form of 2n (for some n initially), the log​​​​2 will return a real number. But variable p can have the value that is of type integer only, as for each iteration in the while loop, the value of p is just incremented by 1.

For example if the x value is 3, then the value of p will be 2 according to the algorithm. But the actual value of log​​​​23=1.5849.

b. Algorithm is fully correct.

In the while loop, in each iteration the value x that is obtained in the previous iteration is divided by 2. If the value is in the form of 2^n then only x will become 1 at the end. Thus returning true. Otherwise at the end it will be some rational value less than 1. Hence it will return false.

please give me like

Add a comment
Know the answer?
Add Answer to:
Determine whether each of the following algorithms is fully correct, and prove that your answer is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT