Answer:
(a) The algorithm is as follows:
count = 0
for i = 1 to n:
if x = xi:
count++
print(count)
(b) n comparisons
Step-by-step explanation:
Solving (a):
Assume the integer to locate is x and the elements of the list are:
Such that:
The algorithm is as follows:
count = 0
for i = 1 to n:
if x = xi:
count++
print(count)
The above iterates through the count of the list (i.e. n) and makes comparison with each element of the list (i.e. element 1 to element n).
When a match is found, the count variable is incremented by 1 and printed at the end of the loop
Furthermore:
If there are 3 elements in the list, the algorithm makes 3 comparisons.
It makes 10 comparisons if there are 10 elements in the list.
So: it makes n elements if there are n elements in the list