Stealing from Biologists to Compile Haskell Faster
iankduncan.com
iankduncan.com
So this can actually be implemented in GHC? I've only read through this once so far and not understood more than ¼, but the section right before the conclusion made it seem like the best you can do is O(n^2.82) along with a huge constant.
It's always fun when someone asks an interview question that's even tangentially related and I get to go deep about the relative tradeoffs of a simpler algorithm like Tarjan's/Dijkstra's, over one of the more modern and faster but conceptually more challenging versions.
I'm not sure I follow. If I had to write a greedy algoritm for this I would do a topological sort in O(n²) and then set the level of each expression to one bigger than the maximum level of its dependencies (again O(n²) worst case)