gives the number of triangles in the graph g.
GraphTriangleCount
gives the number of triangles in the graph g.
Details
- GraphTriangleCount is also known as triangle count and three-vertex clique count.
- GraphTriangleCount is typically used to measure clustering and connectivity in a graph.
- GraphTriangleCount[g] counts cycles of length 3 in the graph g.
Examples
open all close allBasic Examples (2)
Scope (4)
GraphTriangleCount works with undirected graphs:
GraphTriangleCount[[image]]GraphTriangleCount[[image]]Use rules to specify the graph:
GraphTriangleCount[{1 -> 2, 1 -> 3, 2 -> 3, 2 -> 4, 3 -> 1, 3 -> 4}]GraphTriangleCount works with large graphs:
g = ExampleData[{"NetworkGraph", "WorldWideWeb"}];EdgeCount[g]GraphTriangleCount[g]//TimingApplications (1)
Compute the transitivity of a graph:
g = ExampleData[{"NetworkGraph", "USPoliticsBooks"}];3 GraphTriangleCount[g] / Sum[d (d - 1) / 2, {d, VertexDegree[g]}]Compare with GlobalClusteringCoefficient:
GlobalClusteringCoefficient[g]Properties & Relations (2)
Use MatrixPower to count triangles in a graph:
g = ExampleData[{"NetworkGraph", "FamilyGathering"}];Tr[MatrixPower[AdjacencyMatrix[g], 3]] / 6GraphTriangleCount[g]Use FindCycle to list triangles in a graph:
g = ExampleData[{"NetworkGraph", "FamilyGathering"}];FindCycle[g, {3}, All]//ShortLength[%]GraphTriangleCount[g]History
Text
Wolfram Research (2024), GraphTriangleCount, Wolfram Language function, https://reference.wolfram.com/language/ref/GraphTriangleCount.html.
CMS
Wolfram Language. 2024. "GraphTriangleCount." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/GraphTriangleCount.html.
APA
Wolfram Language. (2024). GraphTriangleCount. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GraphTriangleCount.html
BibTeX
@misc{reference.wolfram_2026_graphtrianglecount, author="Wolfram Research", title="{GraphTriangleCount}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/GraphTriangleCount.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_graphtrianglecount, organization={Wolfram Research}, title={GraphTriangleCount}, year={2024}, url={https://reference.wolfram.com/language/ref/GraphTriangleCount.html}, note=[Accessed: 12-June-2026]}