GraphQ
Examples
open all close allBasic Examples (2)
Test whether an object is a valid Graph object:
Graph[{12, 23, 31}]GraphQ[%]A Graphics object that contains a picture of a graph is not a valid Graph object:
GraphPlot[{1 -> 2, 2 -> 3, 3 -> 1}]GraphQ[%]Scope (6)
GraphQ works with undirected graphs:
GraphQ[[image]]GraphQ[[image]]GraphQ[[image]]GraphQ[[image]]GraphQ gives False for anything that is not a graph:
GraphQ[x]GraphQ[Graph[garbage]]GraphQ works with large graphs:
GridGraph[{10, 10, 10, 10}];GraphQ[%]//TimingProperties & Relations (5)
Test whether a graph is directed or undirected:
{g1, g2} = {Graph[{12, 23, 31}], Graph[{12, 23, 31}]}UndirectedGraphQ /@ {g1, g2}DirectedGraphQ /@ {g1, g2}Test whether a graph is simple:
{Graph[{12}], Graph[{12, 22}]}SimpleGraphQ /@ %{Graph[{12}], Graph[{12, 22}]}LoopFreeGraphQ /@ %Test whether a graph is bipartite:
{Graph[{12, 23, 31}], Graph[{12, 23}]}BipartiteGraphQ /@ %Test whether a graph is weighted:
{AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
| 1 | 0 | 0 |)], WeightedAdjacencyGraph[(| | | |
| - | - | - |
| ∞ | 1 | ∞ |
| ∞ | ∞ | 3 |
| 2 | ∞ | ∞ |)]}WeightedGraphQ /@ %See Also
Related Guides
History
Text
Wolfram Research (2010), GraphQ, Wolfram Language function, https://reference.wolfram.com/language/ref/GraphQ.html.
CMS
Wolfram Language. 2010. "GraphQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/GraphQ.html.
APA
Wolfram Language. (2010). GraphQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GraphQ.html
BibTeX
@misc{reference.wolfram_2026_graphq, author="Wolfram Research", title="{GraphQ}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/GraphQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_graphq, organization={Wolfram Research}, title={GraphQ}, year={2010}, url={https://reference.wolfram.com/language/ref/GraphQ.html}, note=[Accessed: 13-June-2026]}