Efficient way to recursively calculate dominator tree?

前端 未结 4 936
渐次进展
渐次进展 2021-02-05 11:22

I\'m using the Lengauer and Tarjan algorithm with path compression to calculate the dominator tree for a graph where there are millions of nodes. The algorithm is quite complex

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 11:58

    Judging by the lack of comments, I guess there aren't many people on Stackoverflow with the relevent experience to help you. I'm one of those people, but I don't want such an interesting question go down with with a dull thud so I'll try and lend a hand.

    My first thought is that if this graph is generated by other compilers would it be worth taking a look at an open-source compiler, like GCC, to see how it solves this problem?

    My second thought is that, the main point of your question appears to be avoiding recomputing the result for the root of the tree.

    What I would do is create a wrapper around each node that contains the node itself and any pre-computed data associated with that node. A new tree would then be reconstructed from the old tree recursively using these wrapper classes. As you're constructing this tree, you'd start at the root and work your way out to the leaf nodes. For each node, you'd store the result of the computation for all the ancestory thus far. That way, you should only ever have to look at the parent node and the current node data you're processing to compute the value for your new node.

    I hope that helps!

提交回复
热议问题