Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. x and y are positive integers. Suppose the binary representation of z and y i

ID: 3878100 • Letter: 2

Question

2. x and y are positive integers. Suppose the binary representation of z and y is given by x = x', , . . . , x 1.20 an 191 We can treat a and y as arrays with an index starting at 0 and each array entry is either compute(x, y) 2 for i _ n downto 0 if 1 then 6 return Q (a) Execute the algorithm compute (21, y) and show steps (let x = 21 and y be inde- terminate. What does compute (21,y) do? In general what does compute(x,y) do? oWhat is the invariant property of the for loop (that starts in line 2)? (c) Prove that the algorithm is correct

Explanation / Answer

b)

loop invariant is the condition, that necesarly true before the loop iteration and after the loop iteration

here loop invariant is, value of i should be greater than of equal to 0, i>=0

i moves from i=n to 0 and every time left shifts the value of Q

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote