Asked by Compstudent
                How many elementary operations are used in the following algorithm? 
Step 1 Set S = a, k = 0 , and t = a
Step 2 while k < n
(a) Replace t with t+d
(b) Replace S with S+t
(c) Replace k with k+1
endwhile
Step 2 Print S
------------------------
My answer was: 4*n+1
I don't know if it is right :(
            
        Step 1 Set S = a, k = 0 , and t = a
Step 2 while k < n
(a) Replace t with t+d
(b) Replace S with S+t
(c) Replace k with k+1
endwhile
Step 2 Print S
------------------------
My answer was: 4*n+1
I don't know if it is right :(
Answers
                    Answered by
            bobpursley
            
    if k=>n, there is only one operation, the test.
If k<n, then each time the test occurs, there are four operations(test, replace, replace, replace), and one final operation the test.
4n+1 is correct.
    
If k<n, then each time the test occurs, there are four operations(test, replace, replace, replace), and one final operation the test.
4n+1 is correct.
                    Answered by
            Karen
            
    Step 1 Set a=1, b=1, c=2,and k=0
Step 2 while k < n
(a) Replace c with a+b
(b) Replace a with b
(c) Replace k with k+1
endwhile
Step 3 Print b
    
Step 2 while k < n
(a) Replace c with a+b
(b) Replace a with b
(c) Replace k with k+1
endwhile
Step 3 Print b
                                                    There are no AI answers yet. The ability to request AI answers is coming soon!
                                            
                Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.