MathGroup Archive 2009

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

Search the Archive

Re: number of Trangles in a graph-network

Peter Pein schrieb:
> Hi Luca,
> sometimes it seems I'm sitting on my eyes ...
indeed ... :(
> Here is a natural and really speedy way to get the desired result:
> SeedRandom[123];
> rg=RandomGraph[100,2/3];
> this is my last vesion:
> countTriangles[rg]//AbsoluteTiming
> {24.137618,49063}
> And the trace of the third power of the adjacency counts every triangle six 
> times (abc,bca,cab,cba,acb,bac):
> Tr[MatrixPower[ToAdjacencyMatrix[rg],3]]/6//AbsoluteTiming
> {0.201834,49063}
> Peter

a (hopefully) last comment:There should be the option Type->Simple in the call
to To AdjacencyMatrix to avoid problems with 1- and 2-gons inside the graph
(shame on me).


should give correct results.

sorry for being too vague,

  • Prev by Date: Re: Help with an error with NonlinearModelFit, Mathematica 7.0
  • Next by Date: Re: Message passing in mathematica?
  • Previous by thread: Re: number of Trangles in a graph-network
  • Next by thread: Re: How to select several cells