Finding the mode of a few numbers isn't too hard, but if you have a very long list, you'll probably need some code!
To find the mode, you use the following:
current_count = 0
mode_count = 0
for position in range(len(array)):
if array[position] == array[position-1]:
current_count += 1
if array[position] != array[position-1] \
or position == len(array)-1:
if current_count > mode_count:
mode = array[position-1]
mode_count = current_count
current_count = 1
For this approach to be successful, which of the following must be true about your array?
I. It is sorted.
II. It is unimodal.
- The mode is defined as the element which appears most often in a set. If more than one element appears most often, the mode is that set of elements which appear most often.