Answer to Question #45616 in Engineering for mike

Question #45616
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.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS