indegree

Number of edges entering each node of a digraph.

Category: Mathematics > Graph and Network Algorithms

Syntax

d = indegree(D)

Returns the in-degree of every node.

d = indegree(D, nodeIDs)

Returns the in-degree of the listed nodes only.

Description

A node with in-degree zero is a source: nothing points at it. In a directed acyclic graph there is always at least one source, which is where a topological ordering starts. Summing indegree over all nodes gives numedges(D).

Input arguments

D
A digraph.
nodeIDs
Node indices or names.

Output arguments

d
Column vector with the number of edges that end at each node.

Example

Sources and sinks

D = digraph([1 1 2 3 4], [2 3 4 4 5]);
indegree(D)'
outdegree(D)'
find(indegree(D) == 0)
Output
ans = 1×5

     0     1     1     2     1
ans = 1×5

     2     1     1     1     0
ans = 1

See also

outdegree degree inedges predecessors