Graphs: find a sink in less than O(|V|) - or show it can't be done

前端 未结 7 979
死守一世寂寞
死守一世寂寞 2021-02-01 10:17

I have a graph with n nodes as an adjacency matrix.

Is it possible to detect a sink in less than O(n) time?

If yes, how? If no

7条回答
  •  走了就别回头了
    2021-02-01 10:27

    There are so many algorithms that shows how to find the universal sink in O(n) but they are so complex and couldn't be understood easily. I have found it on internet in paper that shows how to find a universal sink in O(n) very smoothly.

    1) first create a "SINK" set consisting of all vertices of the graph also 
       create an adjacency list of the graph.
    2) now choose first 2 elements of the set.
    3) if(A(x,y)==1){
           remove x;             // remove x from "SINK" set.
         }else{
           remove y; }           //remove y from "SINK" set.B
    

    By this algo you will end up with the sink node in your SINK set in "n-1" time. that is O(n) time.

提交回复
热议问题