CAPE 2012 U1 Q3 Solution

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s