2012 U1 Q3
Part A
Algorithms are used to solve computational problems and are a technique for precisely documenting the solution.
Part B
i) Bounded, since the number of iterations are constant every time the algorithm is applied. In this case, the loop is executed 16 times.
ii) Unbounded, since the number of iterations is not set and is dependent on the value of a sentinel variable, in this case X
Part C)
START
rcount, bcount,gcount,ncount <--0
for i<-- 1 to 150 do
input vote
if (vote = "red") then
rcount++
else if (vote = "green") then
gcount++
else if (vote = "blue") then
bcount++
else
ncount++
endif
endfor
output "total votes for color = " + rcount+gcount+bcount
output rcount " voted for red"
output bcount " voted for blue"
output gcount " voted for green"
END
Part d

Alternatively, in Pseudocode:

© 2020 Vedesh Kungebeharry. All rights reserved.