I have been attempting an algorithm which runs in O(w) time, where w is the length of a word I am attempting to find in a list of alphabetically ordered words. Space is not a concern. I have found some information on using a Trie to find the word in O(w) time, but I am not sure if this time includes the amount of time required to build the Trie itself? Say I have an array of alphabetically sorted words, S, and I want to find a word w, S has n words, w is of length m. Here is what I have so far:
1. build Trie, T, from S // O(?) time
2. search for w in T // O(m) time
I would like to find a way to keep step 2 in constant time so my total time complexity will be O(m). Is there a way to do this? If so, I only need some guidance on how to set this up. If not, is there another data structure I am forgeting about? Space consumption is not an issue. I can use as much space as needed to get the algorithm to run in O(w), which I can't seem to do, unless I can setup a Trie in constant time.
I have found this post stating the time to create a Trie is O(n*l) where l is the avg length of words in S. This maybe tells me I need to use a different data structure for my solution, but I cannot determine which other data structure type would fit my problem.