Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting the sink in a directed acyclic graph

Let's say that there is one vertex with the following property in a DAG:

  1. All vertices are connected to it

  2. It is not connected to any vertex

This is usually called a sink vertex.

Is it possible to detect this vertex in O(n), where n is number of vertices in graph?

like image 442
Rohan Monga Avatar asked Nov 09 '10 19:11

Rohan Monga


People also ask

What is a sink in a DAG?

In a DAG, a source is a vertex without incoming edges; a sink is a vertex without outgoing edges.

What is a sink in a directed 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).

Does a DAG have a source and sink?

(A) Every DAG G has at least one source and at least one sink.

How do you find the universal sink on a graph?

To eliminate vertices, we check whether a particular index (A[i][j]) in the adjacency matrix is a 1 or a 0. If it is a 0, it means that the vertex corresponding to index j cannot be a sink. If the index is a 1, it means the vertex corresponding to i cannot be a sink.


1 Answers

As there are no cycles in the graph, and all vertex connect with the sink, just select any starting node and start walking randomly. When you can't continue walking, you are at the sink, in at most n steps.

Once you walked n steps (or less and you can't continue), as the problem does not guarantee that there is a sink, you should check if you are at one. That adds another O(n). So the problem is O(2 n) = O(n)

like image 81
Dr. belisarius Avatar answered Sep 24 '22 02:09

Dr. belisarius