title: What is an efficient algorithm for counting the number of triangles in a graph?
body: <p>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. </p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>I'm currently working in C#, but care more about the general approach towards solving this problem than code to copy and paste.</p>
  
  <p>At the high level, my attempts thus far included:</p>
  
  <ul>
  <li>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</li>
  <li>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).</li>
  </ul>
  
  <p>The algorithm itself is part of calculating the clustering coefficient.</p>