Algorithm for topological sorting if cycles exist

后端 未结 2 1291
野趣味
野趣味 2021-01-31 21:47

Some programming languages (like haskell) allow cyclic dependencies between modules. Since the compiler needs to know all definitions of all modules imported while compiling one

2条回答
  •  忘了有多久
    2021-01-31 22:20

    This is the NP-hard (and APX-hard) problem known as minimum feedback vertex set. An approximation algorithm due to Demetrescu and Finocchi (pdf, Combinatorial Algorithms for Feedback Problems in Directed Graphs (2003)") works well in practice when there are no long simple cycles, as I would expect for your application.

提交回复
热议问题