the many fit proceed tip k revisit difference large sequence


input: certain integer k large text. calm indeed beheld sequence. don't have worry smack down sequence.

output: many revisit k difference text.



my pondering this.




  1. use crush list record words' magnitude while camber whole sequence. phase, pivotal "word" value "word-frequency". takes o(n) time.


  2. sort (word, word-frequency) pair; pivotal "word-frequency". takes o(n*lg(n)) normal classification algorithm.


  3. after sorting, only take initial k words. takes o(k) time.




to summarize, sum o(n+nlg(n)+k) given k definitely smaller n, indeed o(nlg(n)).



we provoke this. actually, only wish tip k words. words' magnitude pleasantness us. so, "partial store sorting". step 2) 3), don't only sorting. instead, change be



2') build store (word, word-frequency) camber "word-frequency" key. takes o(n) build heap;



3') mislay tip k difference heap. any skirmish o(lg(n)). so, sum o(k*lg(n)).



to summarize, fortitude cost o(n+k*lg(n)).



this only thought. i haven't out proceed provoke step 1).

i wish information retrieval experts broadcast some-more light question.



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?