An alien language writes with our letters but sorts them in an order nobody told you. All you have is a list of its words, already in dictionary order. Each pair of neighboring words gives at most one clue about which letter comes first, the clues form a directed graph, and any topological order of that graph is an alphabet that fits.
A dictionary sorts by the first letter where two words differ. So walk each neighboring pair left to right until the letters disagree. That position is the only clue the pair gives: the top word's letter comes before the bottom word's letter. Everything after it was never used to sort the pair, so it tells you nothing.
How to read this: each box holds two neighboring words. We compare them letter by letter, and the first letters that differ (gold) tell us which letter comes first in the alien alphabet.
Try this: press Step a few times and watch where the gold letter lands in each pair. In the Clues list, gold chips are new clues and dim ones are repeats.
Each letter is compared at most once, so the work is bounded by C, the total number of letters in the list. With n words there are n − 1 pairs and at most n − 1 clues.
Draw each letter as a node and each clue x → y as an arrow. The badge on a node is its in-degree: how many letters still have to be placed before it. Kahn's algorithm repeatedly takes a letter whose badge reads 0, writes it down, and removes its outgoing arrows. The letters come out in gold, in order.
How to read this: an arrow x → y means x comes before y. The small badge on each letter counts arrows still pointing into it; when it hits 0 the letter is free to be written next. Letters are laid out left to right by how many must come before them.
Try this: pick "one loose letter", then Step and watch the queue hold two letters at once.
The run is the same Kahn's algorithm as in 019 · Topological sort, fed by a graph built from words. More graph algorithms live in 002 · Graphs.
Not every word list can come from a real dictionary. Two things break it: a word placed after a longer word that starts with it, and clues that chase each other in a circle. A third case looks odd but is fine: letters that appear in the words and never get a clue. Pick a preset or type your own list, then run the full check.
How to read this: the top row shows each neighboring pair and the clue it gives (gold), or "·" for none. Below, arrows are clues; if they chase each other in a loop, no alphabet can work.
Try this: run "three-letter cycle", then "free letters", and compare the verdicts.
Prefix second. Any real dictionary puts ab before abc, because running out of letters counts as smaller than any letter. No alphabet can put abc first, so the answer is "no order". The reverse, a prefix placed first, is normal and gives no clue.
A cycle. Clues a → b, b → c, c → a would need a before itself. Kahn's algorithm detects this without searching for it: every letter on the cycle keeps an in-degree of at least 1, the queue empties early, and fewer letters come out than went in. Letters downstream of the cycle get stuck too.
No clue. A letter with no arrows starts at in-degree 0 and can go anywhere in the alphabet. That is still a valid answer, just one of many.