This is an offline algorithm. Take a look at GNU gperf[1].<p>[1]<a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;gperf&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;gperf&#x2F;</a>