for i = 1 to n do low = roster[i]quiz[1] sum = roster[i]quiz[1] high = roster[i]
ID: 3589576 • Letter: F
Question
for i = 1 to n do
low = roster[i]quiz[1]
sum = roster[i]quiz[1]
high = roster[i]quiz[1]
for j = 2 to m do
sum = sum + roster[i].quiz[j]
if roster[i].quiz[j] < low then
low = roster[i]quiz[j]
end if
if roster[i].quiz[j] > high then
high = roster[i].quiz[j]
end if
end for
sum = sum - low
sum = sum + high
write("Total Students is ", i, "is" sum)
end for
Question: What is the total number of arithmetic operations done in the algorithm?
Explanation / Answer
ANSWER
In the above program arithmetic operations declared for 3 times and we have 2 for loops
so in first for loop we have iterations for n and in that 2 arithmetic operations.
in second for loop we have iterations for m-1 and in hat 1 arithmetic operations we have.
So for the first loop for n iterations 2 times arithmetic operation performed i.e., 2 * n times
in second loop for m-1 iterations 1 time arithmetic operation performed i.e., 1 * (m-1)
So from the above algorithm total no. of arithmetic operations done is 2n+(m-1)
Thank you for given oppurtunity to answer
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.