Question

DIVISIBLEBYNINE (x) 1 if x< 10 then if x 0 or x 9 then return yes else return no 5 els while x> 0 do y y (x mod 10) Lx/10 X return DIVISIBLEBYNINE (y)

a. Argue that the algorithm always terminates, that is, that the algorithm does not call itself

recursively until all eternity. (Hint: Prove that the value of y in Line 9 is less than the value of

x at the beginning of the procedure and draw the right conclusions.)

b. Prove that the algorithm always gives the correct answer. (Hint: Use induction. For the

inductive step, argue that y is divisible by 9 if and only if this is true for x. Use the fact that 9

divides 10^k − 1 for any integer k.)

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

o) hebus prove bh.s by endoction on χ OH X410 olgowilhn olovtiousl tenminates becaupe i Creutes one to lines and, uhich take2, s o and 10 b) Wet us pHove bhit by ind ion bnwe becoude o and aye only two numbes less than o and disible b we can aeo ume2 s not chulisble t, Lien whete yand tr t 1 olbo leave manywhn druided by druisible by9 and no anwe hetonned T is ogan ct On

Add a comment
Know the answer?
Add Answer to:
a. Argue that the algorithm always terminates, that is, that the algorithm does not call itself...
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