Prefix Tree vs Hash Table

Feb 23, 2020 11:33

Prefix trees are known as an alternative implementation for dictionaries/maps. Applied like this, they sometimes significantly outperform hash tables. In particular, it works well when key space consists of thousands not-very-long strings. I saw this in action as a part of a smart order router code at a big sell-side firm where the keys were US ( Read more... )

golang, coding interview, algorithm, go

Leave a comment

Comments 23

morfizm February 23 2020, 22:33:20 UTC
Nice application of prefix trees!

Reply

aklepatc February 23 2020, 23:15:39 UTC
Thank you!

Reply


yatur February 24 2020, 03:19:36 UTC
Nice research, thanks!

Have you gathered any statistics on how much the prefix tree is faster than dictionary search?

As for Aho-Corasick, I think it should be possible to build a big regular expression along the lines of "(C\+\+)|(Java)|(\.Net)|(Data Integration)", match against it, and then iterate over the list of matched subgroups to assign the resume to the corresponding bucket(s). E.g. if the text matches subgroup 0 and subgroup 2, it goes to "C++" and ".Net" buckets. I am quite positive that the algorithm used in RegExes is similar to Aho-Corasick (a linear state machine), but you won't need to code it by hand.

Reply

aklepatc February 24 2020, 14:30:39 UTC
My benchmark shows prefix tree to be 2.5-3 times faster than map[string]*something in Go. That scenario I'm testing for is rather language and application specific. So I would not call any of this "statistics". More like war story or professional anecdote : )

Reply

yatur February 24 2020, 17:50:41 UTC
2-3 times is impressive indeed, even if it's for some specific case.

Reply

aklepatc February 24 2020, 18:25:44 UTC
Based on the previous experiences with Go standard library (vs my custom implementations), I hoped for 10 times, TBH. So 2-3 felt like a minor disappointment...

Reply


zveriozha February 24 2020, 06:45:03 UTC
Давненько вас не было. :)

Reply

aklepatc February 24 2020, 14:42:15 UTC
Верно. Интересные (даже мне самому) мысли, к сожалению, не часто приходят в голову. В основном, сплошная рутина.

Reply

zveriozha February 24 2020, 14:48:53 UTC
А вы в фейсбуке не сидите?

Reply

aklepatc February 24 2020, 14:57:16 UTC
Нет. Когда мне что-то нужно посмотреть в ФБ, я прошу у жены заглянуть в её account : )

Вот на Tommy Carruthers иногда смотрю, по вашей рекомендации.

Reply


Leave a comment

Up