Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prove the correctness of the following algorithm- if, in fact, it is correct. Since it is recursive, we expect that mathematical induction will be used.

Prove the correctness of the following algorithm- if, in fact, it is correct. Since it is recursive, we expect that mathematical induction will be used. Before launching into an attempted proof, you should first try to decide if it has a chance of being correct.

Multiply(y, z)

// Precondition: y and z are non-negative integers.

// Postcondition: Multiply(y, z) = yz.

// Note: c 2 is an integer - some constant we choose.

if z == 0

return 0

else

return Multiply(cy, floor (z/c)) + y . (z mod c)

(a) Do you believe the algorithm is correct for all pairs of values (y, z) which satisfy the precondition? Do not be concerned with issues of computer arithmetic such as overflow. If you think the algorithm is incorrect, give a counter-example which shows an incorrect result. If this is the case, how might you fix the algorithm? If you think the algorithm is correct provide some evidence in the form of a couple of simple invocations of the function carried through to conclusion with the correct product returned.

(b) Prove the original algorithm (or your corrected version if you do not think the original is correct) does successfully compute the product.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions