If this is simply an operation you wish to do on it's own (rather than a component you want to use), the most practical way for me would be to do something like this:
sort <filename> | uniq -c | sed 's/^[ \t]*//' | sort -rn
Of course it doesn't scale well compared to a linear algorithm, but it performs reasonably well for every day tasks, and it has the added advantage that you don't need to reinvent the wheel yourself.
EDIT: sort" sorts your file ; "uniq" groups all consecutive lines that are the same into a pair [frequency] [item] pair, for instance
12
12
24
25
25
25
becomes
2 12
1 24
3 25
then I remove the trailing space with "sed" (if this doesn't work, it is because there is sometimes an issue with the way the tab character is inputted), then I sort the output according to frequency (the "n" option asks for a numerical sort, instead of lexicographic; the "r" option asks for a reverse sorting).
If you want to select another field for the sorting (say, because the number you are actually interested in counting the frequency are the THIRD field of a tab delimited line), then you can use "sort"'s selection feature:
sort -t'\t' -k3 <filename> | ...
This says that your input is a tab-delimited list of fields, and that you want to sort according to the third field.
EDIT 2: here is the line to do this according to the fourth field (and to remove all other fields)
cut -d'\t' -f4 <filename> | sort | uniq -c | sed 's/^[ \t]*//' | sort -rn