Data structure behind T9 type of dictionary

前端 未结 6 1716
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 11:34

How does a T9 dictionary work? What is the data structure behind it. If we type \'4663\' we get \'good\' when we press down button we get \'gone\' then \'home\' etc...

6条回答
  •  攒了一身酷
    2020-12-07 12:04

    I'd probably do it by starting with a dictionary, then (for each word) push the word onto a list keyed by the numbers that could form the word.

    Then, you'll probably need to sort the resulting lists in some fashion, so more likely words appear before less likely words (if you have the space, I'd also include a small area for a counter, so we can incrementally re-sort these OR simply mov ethe last used to the front of the suggestion list, so we, over time, tend towards giving the user a better answer).

    That way, when you have 4663 as an input, you can quite simply retrieve the relevant linked list wit ha roughly O(1) hash table lookup.

提交回复
热议问题