-1

If a word is typed in Google, it will show a list of words as suggestions in a drop-down list.

For example, if you type what, it will show what is your name, what is your father's name, what is your college name, etc. in 8 words.

What is a suitable data structure, as well as best way to list those suggestions?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Pixel
  • 419
  • 4
  • 7
  • 17

1 Answers1

1

I think the best method is to use a trie where each edge is weighted according to the probability that the next letter correspond to this edge so that first suggestions have higher probabilities.

Thomash
  • 6,339
  • 1
  • 30
  • 50