igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] how to determine the number of unique child nodes in a tree


From: Tamás Nepusz
Subject: Re: [igraph] how to determine the number of unique child nodes in a tree
Date: Fri, 13 Jul 2012 10:09:48 +0200

Hi, 

>  
> Given some tree and a reference position in that tree, I would like to
> be able to query the graph to identify the unique terminal child nodes.

I presume that "terminal child nodes" means "nodes reachable from the given 
start point that have no further children". Assuming that the edges of the tree 
are directed downwards, you can run a single-source shortest path search from 
the start node (igraph_shortest_paths in C, Graph.shortest_paths() in Python, 
shortest.paths in R) and extract the nodes that have a finite distance from the 
start node. From this set, you can simply remove those that have non-zero 
out-degree.

E.g., in R:

reachable <- which(shortest.paths(g, start.node, mode="out") != Inf)
terminal.nodes <- reachable[which(degree(g, reachable, mode="out") == 0)]

Cheers,
T.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]