4.2. igraph_subgraph — Creates a subgraph with the specified vertices.

int igraph_subgraph(const igraph_t *graph, igraph_t *res, 
		    const igraph_vs_t vids);

This function collects the specified vertices and all edges between them to a new graph. As the vertex ids in a graph always start with one, this function very likely needs to reassign ids to the vertices.

Arguments: 

graph:

The graph object.

res:

The subgraph, another graph object will be stored here, do not initialize this object before calling this function, and call igraph_destroy() on it if you don't need it any more.

vids:

Vector with the vertex ids to put in the subgraph.

Returns: 

Error code: IGRAPH_ENOMEM, not enough memory for temporary data. IGRAPH_EINVVID, invalid vertex id in vids.

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

See also: 

igraph_delete_vertices() to delete the specified set of vertices from a graph, the opposite of this function.