How to predict the next word in a sentence using N-grams
Store the n-grams in a tree or trie, with one level per word, starting from the leftmost word.  Then given some context, e.g., "I want to", you traverse the tree/trie (follow the edge out of the root that is labelled "I", then the edge labelled "want", then the edge labelled "to") and find all children of the resulting node.