That is very impressive JLBorges. Thanks a lot.
The reason I put this topic is to have a brainstorm or discussion.
I want to find out any possible solutions or tips behind the question, which isnot limited by the hashtable.
I think I got rejected by the company since I havenot heard anything from them until now.
That is fine. Maybe I didnot ask them the above questions before I rushed to my hashtable. lol
Anyway, the reason I think about the hash is that there isnot any searching algorithm can be applied to a "string" data structure directly, to my best knowledge. Thus I need to convert the string into an integer or a scale before applying any advanced searching algorithm, such as the binary search.
Is that correct? Is there anyway we can search a string from a vector directly?
Here let me repeat my question, in case any misunderstanding.
Assume we have a function which returns an index:
1 2 3 4 5 6 7 8
|
int lookup(string symbol)
{
vector<string>::iterator i;
i = find(symbols.begin(), symbols.end(), symbol);
if (i == symbols.end())
throw new exception();
return (i - symbols.begin));
}
|
The code is to look for a "symbol" from "symbols". However, the computational complexity is
O(n) since we need to go through every single symbol in "symbols".
Is there anyway we can reduce the computational complexity?