In prefixes they use setdefault and .add, this could just be style but it might have a performance effect. In the prefix generation you make a lot of compares, they just generate it all making the first "if prefix in prefixes" superfluous. In most other cases the lazy generation of the cache should be an advantage but as soon as most of the cases are used pre-generating the values should be an advantage. Idea for new video, test the effect of the different implementations and comment on why it is so, in this case the complexity of the two solutions are the same, yours is even slightly better as you don't have to generate all prefixes, only those who are actually used.
This is super helpful and very clear explanation! Please make more videos!
Thanks Vince!! I've got about 80 up at the moment, but I'll be pumping more out soon! Subscribe to stay tuned! :)
cool explanation, thanks :)
nice stuff...waiting for more of such videos
ty! i've probably got about 80 uploaded so far, so plenty to catch up on :D
Nicely explained, thanks!
hashtables are O(1) set get so its very fast to get an item from it
In prefixes they use setdefault and .add, this could just be style but it might have a performance effect.
In the prefix generation you make a lot of compares, they just generate it all making the first "if prefix in prefixes" superfluous.
In most other cases the lazy generation of the cache should be an advantage but as soon as most of the cases are used pre-generating the values should be an advantage.
Idea for new video, test the effect of the different implementations and comment on why it is so, in this case the complexity of the two solutions are the same, yours is even slightly better as you don't have to generate all prefixes, only those who are actually used.
Thank you!
It’s faster because the lookups for sets are ~O(1)