Documentation Center

  • Trial Software
  • Product Updates

Graph::removeVertex

Removes one or several vertices from a graph

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

Graph::removeVertex(G, v)
Graph::removeVertex(G, l)

Description

Graph::removeVertex(G, v) removes vertex v from graph G.

Graph::removeVertex(G, [v1, ..., vn]) removes vertices v1...vn from graph G.

Graph::removeVertex deletes one or several vertices from a graph. A warning is printed if the specified vertex is not contained in the graph.

    Note:   If a vertex is connected to other vertices with edges, they will be removed from the graph, too!

Graph::removeVertex(G, v) removes the vertex v from the graph G.

Graph::removeVertex(G, l) removes all vertices in list l from graph G.

Examples

Example 1

Removing a vertex from a cyclic graph removes also two edges:

G1 := Graph::createCircleGraph(5):
Graph::printGraphInformation(G1)
Vertices: [1, 2, 3, 4, 5]
Edges: [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]
Vertex weights: no vertex weights.
Edge descriptions: no edge descriptions.
Edge weights: no edge weights.
Edge costs: no edge costs.
Adjacency list (out): 1 = [2], 2 = [3], 3 = [4], 4 = [5], 5 = [1]
Adjacency list (in): 1 = [5], 2 = [1], 3 = [2], 4 = [3], 5 = [4]
Graph is directed.
plot(Graph::plotCircleGraph(G1))

G2 := Graph::removeVertex(G1, [1]):
Graph::printGraphInformation(G2)
Vertices: [2, 3, 4, 5]
Edges: [[2, 3], [3, 4], [4, 5]]
Vertex weights: no vertex weights.
Edge descriptions: no edge descriptions.
Edge weights: no edge weights.
Edge costs: no edge costs.
Adjacency list (out): 2 = [3], 3 = [4], 4 = [5], 5 = []
Adjacency list (in): 2 = [], 3 = [2], 4 = [3], 5 = [4]
Graph is directed.
plot(Graph::plotCircleGraph(G2))

If more than one vertex is to be removed they must also be specified in a list:

vertices := [2, 4]:
G3 := Graph::removeVertex(G1, vertices):
Graph::printGraphInformation(G3)
Vertices: [1, 3, 5]
Edges: [[5, 1]]
Vertex weights: no vertex weights.
Edge descriptions: no edge descriptions.
Edge weights: no edge weights.
Edge costs: no edge costs.
Adjacency list (out): 1 = [], 2 = [], 3 = [], 5 = [1]
Adjacency list (in): 1 = [5], 2 = [], 3 = [], 5 = []
Graph is directed.
plot(Graph::plotCircleGraph(G3))

Parameters

l

A list of vertices

v

A vertex

G

A graph

Return Values

Graph

Was this topic helpful?