algorithm - given prefix, how to find most frequently words effiecitly -



algorithm - given prefix, how to find most frequently words effiecitly -

this interview question extended one: http://www.geeksforgeeks.org/find-the-k-most-frequent-words-from-a-file/

but question required on more thing: given prefix

for example, given "bl" homecoming words such "bloom, blame, bloomberg" etc.

so using trie must. then, how efficitnly build heap? it's not right or pratical build heap each prefix @ run time. solution.

[suppose trie or info construction static, pre-build]

thanks!

keep trie words appearing in file , counts. if asked homecoming words prefix "bi", can efficiently using trie formed. since interested in giving occuring words prefix "bi", can utilize min-heap give reply efficiently has been done in post have linked to.

also note since space usage of trie can grow large, can suggest interviewer utilize ternary search tree instead of trie.

algorithm data-structures

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -