How many elementary operations are used in the following algorithm?
Step 1 Set a =1, b = 1, c = 2, k = 1
Step 2 While k < n
(a)replace c with a+b
(b)replace a with b
(c)replace b with c
(d)replace k with k + 1
endwhile
Step 3 Print b
1
Expert's answer
2014-09-05T11:52:01-0400
Step 1: There are 3 operations (3 "="). Step 2: There are 6(n-1)+ n=7n-6 operations. (n-1) times 6 (3 "=" and 3 "+") and n checkings if k<n). Step 3: print() is not elementary operation. Thus we have 3+(7n-6)+0=7n-3 operations. Answer: 7n-3.
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment