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:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
For this approach to be successful, which of the following must be true about your array?
I. It is sorted.
II. It is unimodal.
Details
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The statement (line 4)
will only work if the array is sorted.
Uni modal means something that has only one mode.
If there was more than one mode, an
list
would have been used to store the modes. However, in the code, a int variable is used to store the mode. Hence it's unimodal.Additionally, the following statement (line 8)
only works when
current_count
is greater thanmode_count
.However, if there was more than one mode, then something like this -
would have been required.