How to convert an undirected graph to a DAG?

前端 未结 4 1494
情深已故
情深已故 2021-02-08 07:40

The Wiki page says

Any undirected graph may be made into a DAG by choosing a total order for its vertices and orienting every edge from the earlier endpo

4条回答
  •  遇见更好的自我
    2021-02-08 08:17

    Actually I think what it means in the wiki page by "choosing a total order" means defining a total order yourself. In other words, if we check the simplest undirected graph:

    A----B
    

    Converting this undirected graph to a DAG clearly depends on whether you choose to order A before B or A after B. If you choose A before B, then it becomes:

    A--->B
    

    Otherwise, it becomes:

    B--->A
    

    That is exactly what it means by "orienting every edge" from the "EARLIER" endpoint (endpoints that appear earlier in the total order) to the "LATER" endpoint.

    Similarly, for:

        A
       / \
      /   \
     B-----C
    

    If you define the total order as:

    B A C
    

    Then the directed graph should be something like:

    B->A, B->C, A->C
    

提交回复
热议问题