The frequency queue data structure
My previous endeavor into byte pair encoding didn’t go anywhere worth writing about, but it posed an interesting problem: design a data structure from which you can query and remove the mode, or the element that appears most often. We can treat the number of appearances, or frequency, as a priority and use a binary heap for O(log n) operations. But we can exploit certain properties of frequencies to do better. This article introduces a “frequency queue” data structure with O(1) operations that is arguably easier to implement than a binary heap.