Consider the following algorithmic procedure: Input :Non-negative integers x, y Output :Non-negative integer r:= x; s:= y; a := 0; while s #0 do if 3 |s then

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Hello! I need your help with the question attached (3rd Question). Please show the work done. Thank you! 

Consider the following algorithmic procedure:
Input :Non-negative integers x, y
Output :Non-negative integer a
r:= x;
s:= y;
a := 0;
while s + 0 do
if 3 | s then
r:=r+r+r;
s:= s/3;
end
else if 3| (s - 1) then
a := a+r;
r:=r+r+r;
s:= (s – 1)/3;
end
else
a := a+r+r;
r:=r+r+r;
s:= (s – 2)/3;
end
end
return a
Algorithm 1: Multiply
We can model Algorithm 1 as a state machine whose states are triples of non-negative integers
(r, s,a). The initial state is (x, y, 0). The transitions are given by the rule & that for s > 0:
(3r, s/3,a)
8(r, s, a) = {(3r, (s – 1)/3,a+r)
if 3 | s
if 3 | (s – 1)
(3r, (s – 2)/3,a+ 2r) otherwise.
1. List the sequence of steps that appears in the execution of the algorithm for inputs x = 5
and y = 10. In other words, walk us through the algorithm starting from the initial state and
ending with the final state.
2. Verify the partial correctness of Algorithm 1.
(a) Define a predicate P on the states that you believe is a preserved invariant. (Suggestion:
Think about why the loop condition is s # 0 and look at your sequence of steps from
Part 1.)
(b) Prove that P is a preserved invariant.
(c) Apply the Invariant Principle to prove that if s = 0, then a = xy.
3. Verify that Algorithm 1 terminates.
(a) Define a strictly decreasing derived variable on the states.
(b) Prove that the algorithm terminates after at most 1+ log, y executions of the body of the
do statement.
Transcribed Image Text:Consider the following algorithmic procedure: Input :Non-negative integers x, y Output :Non-negative integer a r:= x; s:= y; a := 0; while s + 0 do if 3 | s then r:=r+r+r; s:= s/3; end else if 3| (s - 1) then a := a+r; r:=r+r+r; s:= (s – 1)/3; end else a := a+r+r; r:=r+r+r; s:= (s – 2)/3; end end return a Algorithm 1: Multiply We can model Algorithm 1 as a state machine whose states are triples of non-negative integers (r, s,a). The initial state is (x, y, 0). The transitions are given by the rule & that for s > 0: (3r, s/3,a) 8(r, s, a) = {(3r, (s – 1)/3,a+r) if 3 | s if 3 | (s – 1) (3r, (s – 2)/3,a+ 2r) otherwise. 1. List the sequence of steps that appears in the execution of the algorithm for inputs x = 5 and y = 10. In other words, walk us through the algorithm starting from the initial state and ending with the final state. 2. Verify the partial correctness of Algorithm 1. (a) Define a predicate P on the states that you believe is a preserved invariant. (Suggestion: Think about why the loop condition is s # 0 and look at your sequence of steps from Part 1.) (b) Prove that P is a preserved invariant. (c) Apply the Invariant Principle to prove that if s = 0, then a = xy. 3. Verify that Algorithm 1 terminates. (a) Define a strictly decreasing derived variable on the states. (b) Prove that the algorithm terminates after at most 1+ log, y executions of the body of the do statement.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Customer conflict
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education