Seeking algorithm to invert (reverse? mirror? turn inside-out) a DAG

后端 未结 5 1430
我寻月下人不归
我寻月下人不归 2021-02-01 09:54

I\'m looking for an algorithm to \"invert\" (reverse? turn inside-out?) a DAG:

       A*      # I can\'t ascii-art the arrows, so just
      / \\      # pretend          


        
5条回答
  •  名媛妹妹
    2021-02-01 10:27

    My intuitive suggestion would be to perform a Depth First traversal of your graph, and construct your mirrored graph simultaneously.

    When traversing each node, create a new node in the mirrored graph, and create an edge between it and its predecessor in the new graph.

    If at any point you reach a node which has no children, mark it as a root.

提交回复
热议问题