IsTree

IsTree()

A graph method that determines if a graph is a connected tree. The function returns a list of [bool, int], where the bool indicates whether the graph is a tree and the int is the node id for the root of the tree. The method works with TNGraph and TNEANet.

Parameters:

  • none

Return value:

  • list: [bool, int]

    The list consists of two elements: a bool that indicates whether the graph is a tree, and an int giving the node id for the root of the tree.

The following example shows how to detect trees in TNGraph and TNEANet:

import snap

Graph = snap.GenTree(snap.TNGraph, 3, 3)
[is_tree, root_id] = Graph.IsTree()
print("The graph is a tree: %s " % is_tree)
print("The graph has a root id: %d" % root_id)

Network = snap.GenTree(snap.TNEANet, 3, 3)
[is_tree, root_id] = Network.IsTree()
print("The graph is a tree: %s " % is_tree)
print("The graph has a root id: %d" % root_id)