I have a very large array (around 50 000 elements, consisting of single words). I would like to be able to get the most commonly used words, and their frequency in the shortest possible time. The problem with my current method is that:
- 25 elements takes 0 seconds
- 250 elements takes 0 seconds
- 2 500 elements takes 1 second
- 25 000 elements takes 30 seconds
- 50 000 elements takes a minute and a half.
It's not hard to see, that this goes up exponentially, and I'm pretty sure that is because of my method. So my question is whether it is possible to do this in a linear amount of time. The result can be any data format, array of objects, or one object,