Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an efficient algorithm for counting the number of triangles in a graph? [closed]

What is an efficient algorithm for counting the number of triangles in an undirected graph )(where a graph is a set of vertices and edges)? I've been searching Google and reading through my shelf of textbooks for a few hours each day for three days in a row.

This is for a homework assignment where I need such an algorithm, but developing it doesn't count for anything on the assignment. It is expected that we can simply find such an algorithm from outside resources, but I'm at the end of my rope.

For clarification, a triangle in a graph is a a cycle of length three. The trick is that it needs to work on vertex sets with at most 10,000 nodes.

I'm currently working in C#, but care more about the general approach towards solving this problem than code to copy and paste.

At the high level, my attempts thus far included:

  • A breadth first search that tracked all unique cycles of length three. This seemed like a fine idea to me, but I couldn't get it functional
  • A loop over all the nodes in the graph to see if three vertices shared an edge. This has far too slow of a running time for the larger data sets. O(n^3).

The algorithm itself is part of calculating the clustering coefficient.

like image 550
XBigTK13X Avatar asked Sep 13 '11 03:09

XBigTK13X


People also ask

How do you count the number of triangles on a graph?

Given an Undirected simple graph, We need to find how many triangles it can have. For example below graph have 2 triangles in it. Let A[][] be the adjacency matrix representation of the graph. If we calculate A3, then the number of triangles in Undirected Graph is equal to trace(A3) / 6.

What is triangle counting algorithm?

The Triangle Count algorithm counts the number of triangles for each node in the graph. A triangle is a set of three nodes where each node has a relationship to the other two. In graph theory terminology, this is sometimes referred to as a 3-clique.

Which algorithm is used in graph?

Some Common Graph AlgorithmsBreadth First Search (BFS) Depth First Search (DFS) Dijkstra. Floyd-Warshall Algorithm.

What is the formula to count triangles?

The number of triangles is 1, 8, 35, 110, 287, 632, 1302, 2400, 4257, 6956 for polygons with 3 through 12 sides. If we connect all vertices of a regular N-sided polygon we obtain a figure with = N (N - 1) / 2 lines. For N=8, the figure is: Careful counting shows that there are 632 triangles in this eight sided figure.


1 Answers

You will need depth first search. The algorithm will be:

1) For the current node ask all unvisited adjacent nodes

2) for each of those nodes run depth two check to see if a node at depth 2 is your current node from step one

3) mark current node as visited

4) on make each unvisited adjacent node your current node (1 by 1) and run the same algorithm

like image 59
evhen14 Avatar answered Nov 09 '22 11:11

evhen14