Advanced Graphs
120 / 170Advanced GraphsLesson 5 of 6About 61 min
The hardest part is not the algorithm. It is working out what the nodes and edges are.
What is a node? What does an edge mean, and which direction does it point? Which inputs produce edges, and which produce nothing? What input is impossible, and how would I detect it?
Four sentences. For the problem below they take five minutes and turn it from a hard problem into a derivation followed by an algorithm you have already written.
This extracts ordering constraints from adjacent words. It produces constraints that the input does not actually imply. Click the line that is wrong.
Extracting constraints from n words of average length L, then topologically ordering the resulting graph over an alphabet of size a. Give the total time and the space for the graph.
for first, second in zip(words, words[1:]): for a, b in zip(first, second): if a != b: pairs.append((a, b)) breakRead the constraints first and let them tell you what complexity is expected. Derive the approach, implement it, run the tests, and submit when it passes.