The algorithm of Triangle Count is as follows:
- Calculate the neighboring nodes of each node.
- Calculate the intersection for each edge and find the node whose id in the intersection is greater than the id of the first two nodes.
- For each node, count the total number of Triangles. Note that only the Triangle Counts that meet the calculation direction are counted.
Note
When calculating triangles, there must be a calculation direction (for example, starting node id <intermediate node id <destination node id).
Assume that node A and node B are neighbors. The set of neighbors of node A is {B, C, D, E}, the set of neighbors of node B is {A, C, E, F, G}, and their intersection is {C, E} . The nodes in the intersection are the common neighbors of node A and node B, so there are two triangles {A, B, C} and {A, B, E}.