WLJS LogoWLJS Notebook

VertexQ

VertexQ[g, v] yields True if v is a vertex in the graph g and False otherwise.

Examples

Check if a vertex exists in a graph:

g = Graph[{1 -> 2, 2 -> 3}];
VertexQ[g, 2]
(* True *)

Non-existent vertex:

VertexQ[g, 5]
(* False *)

With named vertices:

g = Graph[{"a" -> "b", "b" -> "c"}];
VertexQ[g, "a"]
(* True *)

Please visit the official Wolfram Language Reference for more details.

On this page