The counting occurrences algorithm looks through a list of items and counts the number of times (occurrences) that a match is found. It again checks every item in the list and increments a counter when a match is found.
It is important to only output the amount of matches after the entire list has been traversed. The algorithm is just a basic linear search but using a variable to keep a running total when a particular condition is met.
SearchItem = Input from USER
Total = 0
FOR counter = 0 TO Length(array)
IF array(counter) = SearchItem
Total = total +1
END IF
END FOR
it is important to initialise occurrences to 0 before beginning.
This could be used within a function to return the amount of occurrences (which may be 0).