Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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, how do we prove it?

Sink vertex is a vertex that has incoming edges from other nodes and no outgoing edges.

like image 454
flybywire Avatar asked May 11 '09 10:05

flybywire


People also ask

What is a sink in a graph?

A local sink is a node of a directed graph with no exiting edges, also called a terminal (Borowski and Borwein 1991, p. 401; left figure). A global sink (often simply called a sink) is a node in a directed graph which is reached by all directed edges (Harary 1994, p. 201; right figure).

What is a sink vertex in a graph?

Sink vertex is a vertex that has incoming edges from other nodes and no outgoing edges.

What is the time complexity of finding universal sink?

We can even build a full transition matrix in O(E) time. Depending on the data structures, we may find an improvement by a second pass over all edges, but 2 * O(E) is still O(E).

What is universal sink in a graph?

A universal sink is a vertex which has no edge emanating from it, and all other vertices have an edge towards the sink.


2 Answers

Reading the link provided by SPWorley I was reminded of tournament tree algo for finding the minimum element in an array of numbers. The node at the top of the tree is a minimum element. Since the algorithm in the link also speaks about competition between two nodes (v,w) which is succeeded by w if v->w otherwise by v. We can use an algorithm similar to finding minimum element to find out a sink. However, a node is returned irrespective of the existence of a sink. Though, if a sink exists it is always returned. Hence, we finally have to check that the returned node is a sink.

//pseudo code
//M -> adjacency matrix
int a=0
for(int i=1;i<vertices;++i)
{
  if(M[a,i]) a=i;
}

//check that a is sink by reading out 2V entries from the matrix
return a; //if a is a sink, otherwise -1
like image 107
light Avatar answered Nov 03 '22 22:11

light


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"
like image 39
SPWorley Avatar answered Nov 03 '22 21:11

SPWorley