2.3. Adding and Deleting Vertices and Edges

2.3.1. igraph_add_edge — Adds a single edge to a graph
2.3.2. igraph_add_edges — Adds edges to a graph object.
2.3.3. igraph_add_vertices — Adds vertices to a graph.
2.3.4. igraph_delete_edges — Removes edges from a graph.
2.3.5. igraph_delete_vertices — Removes vertices (with all their edges) from the graph.

2.3.1. igraph_add_edge — Adds a single edge to a graph

int igraph_add_edge(igraph_t *graph, igraph_integer_t from, igraph_integer_t to);

For directed graphs the edge points from from to to.

Note that if you want to add many edges to a big graph, then it is unefficient to add them one by one, it is better to collect them into a vector and add all of them via a single igraph_add_edges() call.

Arguments: 

igraph:

The graph.

from:

The id of the first vertex of the edge.

to:

The id of the second vertex of the edge.

Returns: 

Error code.

See also: 

igraph_add_edges() to add many edges, igraph_delete_edges() to remove edges and igraph_add_vertices() to add vertices.

Time complexity: O(|V|+|E|), the number of edges plus the number of vertices.

2.3.2. igraph_add_edges — Adds edges to a graph object.

int igraph_add_edges(igraph_t *graph, const igraph_vector_t *edges,
		     void *attr);

The edges are given in a vector, the first two elements define the first edge (the order is from , to for directed graphs). The vector should contain even number of integer numbers between zero and the number of vertices in the graph minus one (inclusive). If you also want to add new vertices, call igraph_add_vertices() first.

Arguments: 

graph:

The graph to which the edges will be added.

edges:

The edges themselves.

attr:

The attributes of the new edges, only used by high level interfaces currently, you can supply 0 here.

Returns: 

Error code: IGRAPH_EINVEVECTOR: invalid (odd) edges vector length, IGRAPH_EINVVID: invalid vertex id in edges vector.

This function invalidates all iterators.

Time complexity: O(|V|+|E|) where |V| is the number of vertices and |E| is the number of edges in the new, extended graph.

2.3.3. igraph_add_vertices — Adds vertices to a graph.

int igraph_add_vertices(igraph_t *graph, igraph_integer_t nv, void *attr);

This function invalidates all iterators.

Arguments: 

graph:

The graph object to extend.

nv:

Non-negative integer giving the number of vertices to add.

attr:

The attributes of the new vertices, only used by high level interfaces, you can supply 0 here.

Returns: 

Error code: IGRAPH_EINVAL: invalid number of new vertices.

Time complexity: O(|V|) where |V| is the number of vertices in the new, extended graph.

2.3.4. igraph_delete_edges — Removes edges from a graph.

int igraph_delete_edges(igraph_t *graph, igraph_es_t edges);

The edges to remove are given as an edge selector.

This function cannot remove vertices, they will be kept, even if they lose all their edges.

This function invalidates all iterators.

Arguments: 

graph:

The graph to work on.

edges:

The edges to remove.

Returns: 

Error code.

Time complexity: O(|V|+|E|) where |V| and |E| are the number of vertices and edges in the original graph, respectively.

2.3.5. igraph_delete_vertices — Removes vertices (with all their edges) from the graph.

int igraph_delete_vertices(igraph_t *graph, const igraph_vs_t vertices);

This function changes the ids of the vertices (except in some very special cases, but these should not be relied on anyway).

This function invalidates all iterators.

Arguments: 

graph:

The graph to work on.

vertices:

The ids of the vertices to remove in a vector. The vector may contain the same id more than once.

Returns: 

Error code: IGRAPH_EINVVID: invalid vertex id.

Time complexity: O(|V|+|E|), |V| and |E| are the number of vertices and edges in the original graph.