MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: number of Trangles in a graph-network

  • To: mathgroup at
  • Subject: [mg99374] Re: number of Trangles in a graph-network
  • From: Peter Pein <petsie at>
  • Date: Mon, 4 May 2009 06:00:29 -0400 (EDT)
  • References: <gtefaf$197$>

Luca Cinacchio schrieb:
> Greetings,
> having a graph (network, i.e. one created with RandomGraph) wich can have  
> not connected nodes, I would like to count the total number of triangles  
> inside the graph.
> I gave a look to Combinatorica and its related book by Pemmaraju Skiena,  
> but I did'nt find any solution (maybe I am wrong). Do you know if there is  
> a easy way to answer this problem with Mathematica and/or Combinatorica?
> Thanks in advance.

It seems I'm writing too fast today :(

I've got a slightly faster method:

In[2]:= SeedRandom[123];
In[4]:= (* this is from my 1st posting *)
Out[4]= {5.98437,573}

and faster but a little bit more brain-twisting:

In[6]:= Timing@countTriangles[rg]
Out[6]= {0.100006,573}

don't try this with my first method:

In[7]:= Timing[countTriangles[RandomGraph[100,2/3]]]
Out[7]= {16.705,45453}


  • Prev by Date: Re: Can't apply Differences[] to a SparseArray[]?
  • Next by Date: Re: Solving the system with inexact coefficients
  • Previous by thread: Re: number of Trangles in a graph-network
  • Next by thread: Re: number of Trangles in a graph-network