this is my first question on stack overflow. Some quick background, this is not for a school project, just for fun and practice and learning. I’m trying to make a spell checker in C. The problem I’m having is coming up with possible words to replace a misspelled word.
I should also point at that in my courses we haven’t gotten to higher level programming concepts like time complexity or algorithm development. I say that because I have a feeling there are names for the concepts I’m really asking about, I just haven’t heard of them yet.
In other similar posts here most people suggest using the levenshtein distance or traversing patricia trees; would it be a problem to just compare substrings? The (very much inefficient) algorithm I’ve come up with is:
compare the first N characters, where N = length of the misspelled word - 1, to dictionary words (they would be read from a system file into a dynamically allocated array)
if N characters from the misspelled word and a word from a dictionary match, add it to a list of suggestions; if no more matches are found, decrement N
continue until 10 suggestions are found or N = 0
It feels clunky and awkward, but it’s sort of how our textbook suggests approaching this. I’ve read wiki articles on traversing trees and calculating all kinds of interesting things for efficiency and accuracy, but they’re over my head at this point. Any help is appreciated, and thank you for taking the time to read this.
Modern computers are fast, really fast. It would be worthwhile for you to code this up using the algorithm you describe, and see how well it works for you on your machine with your dictionary. If it works acceptably well, then great! Otherwise, you can try to optimise it by choosing a better algorithm.
All the fancy algorithms you read about have one or both of the following goals:
But that’s only important if you’re seriously concerned about performance. There’s nothing wrong with writing your own code to do this. It may not be great, but you’ll learn a lot more than jumping in and implementing an algorithm you don’t understand yet.