Lexicography
Comparing adjacent words reveals precedence. If "abc" comes before "abd", then 'c' comes before 'd'.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Reconstruct the unknown alphabet of an alien language from a sorted dictionary. Build a dependency graph and use Topological Sort to reveal the hidden sequence.
Comparing adjacent words reveals precedence. If "abc" comes before "abd", then 'c' comes before 'd'.
Each precedence relation a → b is a directed edge in our character graph.
We apply Kahn's Algorithm on the character graph. A valid sort order gives the alphabet. A cycle implies no valid order.
Where N is total characters in words and K is alphabet size. We process every char once.