This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

VertexQ

VertexQ
yields True if v is a vertex in the graph g and False otherwise.
Test whether an item is a vertex of a graph:
Test items of various kinds:
Test whether an item is a vertex of a graph:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
 
Test items of various kinds:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
VertexQ works with undirected graphs:
Directed graphs:
VertexQ works with large graphs:
Compare performance with a test based on VertexList:
Check input to a function:
Take the correct action depending on whether an item is a vertex or an edge:
Act on a vertex:
Act on an edge:
Use Graph and VertexQ for fast set membership tests:
Compare with MemberQ:
VertexQ is equivalent to MemberQ[VertexList[g], v]:
The performance of VertexQ is typically higher:
Use VertexIndex to find the position of a vertex in VertexList[g]:
VertexIndex is typically faster than Position:
Use EdgeQ to test whether an edge is part of a graph:
Some vertices do not seem to be recognized:
Membership is tested using SameQ rather than Equal:
By using identical expressions it can still be tested:
New in 8