Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What algorithm to choose [closed]

Tags:

algorithm

asked in a recent interview:

What data structure would you use to implement spell correction in a document. The goal is to find if a given word typed by the user is in the dictionary or not (no need to correct it). What is the complexity?

like image 798
kc3 Avatar asked Mar 06 '26 17:03

kc3


2 Answers

I would use a "Radix," or "Patricia," tree to index the dictionary. See here, including an example of its use to index dictionary words: https://secure.wikimedia.org/wikipedia/en/wiki/Radix_tree. There is a useful discussion at that link of its complexity.

like image 82
Scott Moonen Avatar answered Mar 08 '26 07:03

Scott Moonen


if I'm understanding the question correctly, you are given a dictionary (or a list of "correct" words), and are asked to specify whether an input word is in the dictionary. So you're looking for data structures with very fast lookup times. I would go with a hash table

like image 29
vlad Avatar answered Mar 08 '26 07:03

vlad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!