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

前端 未结 7 981
死守一世寂寞
死守一世寂寞 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:42

    This page answers your exact question. The linear time algorithm is

       def find-possible-sink(vertices):
         if there's only one vertex, return it
         good-vertices := empty-set
         pair vertices into at most n/2 pairs
         add any left-over vertex to good-vertices
         for each pair (v,w):
           if v -> w:
             add w to good-vertices
           else:
             add v to good-vertices
         return find-possible-sink(good-vertices)
    
       def find-sink(vertices):
         v := find-possible-sink(vertices)
         if v is actually a sink, return it
         return "there is no spoon^H^H^H^Hink"
    
    0 讨论(0)
提交回复
热议问题