TheAlgorithms / Ruby

All algorithms implemented in Ruby
MIT License
1.15k stars 289 forks source link

Solving the `Top k most frequent words` problem using a max-heap #196

Closed aparibocci closed 1 year ago

aparibocci commented 1 year ago

This PR aims to add an algorithm to identify the top k most frequent strings given a provided string list of elements. To do this, the algorithm is using a max-heap implementation already existing in this repository.

Time complexity is O(n), where n is the number of words:

O(n) for building the max-heap k*O(logn) for extracting the k most frequent strings