I have a dictionary in an unknown language. I have to find all the characters of this unknown language and lexicographical relation between them. What can be the most efficient way to do this ?
Note :
1. There might be characters starting by which there is no word present in dictionary
2. You can’t assume that the ascii value of characters will be in sorted order
3. There might be some characters among which you can’t find any relation
e.g.
assume that someone don’t know english and our dictionary is:
B
GA
GAS
GBS
GK
SG
Then the solution will be:
A < B < G < S
A < B < K
I suggest you linear solution. O(|all strings in dictionary| + |alphabet|). |s| – length of s