In an application I will have between about 3000 and 30000 strings.
After creation (read from files unordered) there will not be many strings that will be added often (but there WILL be sometimes!). Deletion of strings will also not happen often.
Comparing a string with the ones stored will occur frequently.
What kind of structure can I use best, a hashtable, a tree (Red-Black, Splay,….) or just on ordered list (maybe a StringArray?) ?
(Additional remark : a link to a good C# implementation would be appreciated as well)
It sounds like you simply need a hashtable. The
HashSet<T>would thus seem to be the ideal choice. (You don’t seem to require keys, butDictionary<T>would be the right option if you did, of course.)Here’s a summary of the time complexities of the different operations on a
HashSet<T>of sizen. They’re partially based off the fact that the type uses an array as the backing data structure.O(1), but potentiallyO(n)if the array needs to be resized.O(1)O(1)(given ideal hashtable buckets)Someone correct me if any of these are wrong please. They are just my best guesses from what I know of the implementation/hashtables in general.