2.2. Basic Query Operations

2.2.1. `igraph_vcount` — The number of vertices in a graph
2.2.2. `igraph_ecount` — The number of edges in a graph
2.2.3. `igraph_edge` — Gives the head and tail vertices of an edge.
2.2.4. `igraph_get_eid` — Get the edge id from the end points of an edge
2.2.5. `igraph_neighbors` — Adjacent vertices to a vertex.
2.2.6. `igraph_adjacent` — Gives the adjacent edges of a vertex.
2.2.7. `igraph_is_directed` — Is this a directed graph?
2.2.8. `igraph_degree` — The degree of some vertices in a graph.

2.2.1. `igraph_vcount` — The number of vertices in a graph

```igraph_integer_t igraph_vcount(const igraph_t *graph);
```

Arguments:

 `graph`: The graph.

Returns:

 Number of vertices.

Time complexity: O(1)

2.2.2. `igraph_ecount` — The number of edges in a graph

```igraph_integer_t igraph_ecount(const igraph_t *graph);
```

Arguments:

 `graph`: The graph.

Returns:

 Number of edges.

Time complexity: O(1)

2.2.3. `igraph_edge` — Gives the head and tail vertices of an edge.

```int igraph_edge(const igraph_t *graph, igraph_integer_t eid,
igraph_integer_t *from, igraph_integer_t *to);
```

Arguments:

 `graph`: The graph object. `eid`: The edge id. `from`: Pointer to an igraph_integer_t. The tail of the edge will be placed here. `to`: Pointer to an igraph_integer_t. The head of the edge will be placed here.

Returns:

 Error code. The current implementation always returns with success.

 `igraph_get_eid()` for the opposite operation.

Time complexity: O(1).

2.2.4. `igraph_get_eid` — Get the edge id from the end points of an edge

```int igraph_get_eid(const igraph_t *graph, igraph_integer_t *eid,
igraph_integer_t pfrom, igraph_integer_t pto,
igraph_bool_t directed);
```

Arguments:

 `graph`: The graph object. `eid`: Pointer to an integer, the edge id will be stored here. `from`: The starting point of the edge. `to`: The end points of the edge. `directed`: Logical constant, whether to search for directed edges in a directed graph. Ignored for undirected graphs.

Returns:

 Error code.

 `igraph_edge()` for the opposite operation.

For undirected graphs `from` and `to` are exchangable. Added in version 0.2.

2.2.5. `igraph_neighbors` — Adjacent vertices to a vertex.

```int igraph_neighbors(const igraph_t *graph, igraph_vector_t *neis, igraph_integer_t pnode,
igraph_neimode_t mode);
```

Arguments:

 `graph`: The graph to work on. `neis`: This vector will contain the result. The vector should be initialized before and will be resized. Starting from igraph version 0.4 this vector is always sorted, the vertex ids are in increasing order. `pnode`: The id of the node of which the adjacent vertices are searched. `mode`: Defines the way adjacent vertices are searched for directed graphs. It can have the following values: `IGRAPH_OUT`, vertices reachable by an edge from the specified vertex are searched, `IGRAPH_IN`, vertices from which the specified vertex is reachable are searched. `IGRAPH_ALL`, both kind of vertices are searched. This parameter is ignored for undirected graphs.

Returns:

 Error code: `IGRAPH_EINVVID`: invalid vertex id. `IGRAPH_EINVMODE`: invalid mode argument. `IGRAPH_ENOMEM`: not enough memory.

Time complexity: O(d), d is the number of adjacent vertices to the queried vertex.

2.2.6. `igraph_adjacent` — Gives the adjacent edges of a vertex.

```int igraph_adjacent(const igraph_t *graph, igraph_vector_t *eids,
igraph_integer_t pnode, igraph_neimode_t mode);
```

Arguments:

 `graph`: The graph object. `eids`: An initialized vector_t object. It will be resized to hold the result. `pnode`: A vertex id. `mode`: Specifies what kind of edges to include for directed graphs. `IGRAPH_OUT` means only outgoing edges, `IGRAPH_IN` only incoming edges, `IGRAPH_ALL` both. This parameter is ignored for undirected graphs.

Returns:

 Error code. `IGRAPH_EINVVID`: invalid `pnode` argument, `IGRAPH_EINVMODE`: invalid `mode` argument.

Time complexity: O(d), the number of adjacent edges to `pnode`.

2.2.7. `igraph_is_directed` — Is this a directed graph?

```igraph_bool_t igraph_is_directed(const igraph_t *graph);
```

Arguments:

 `graph`: The graph.

Returns:

 Logical value, ` TRUE` if the graph is directed, ` FALSE` otherwise.

Time complexity: O(1)

2.2.8. `igraph_degree` — The degree of some vertices in a graph.

```int igraph_degree(const igraph_t *graph, igraph_vector_t *res,
const igraph_vs_t vids,
igraph_neimode_t mode, igraph_bool_t loops);
```

This function calculates the in-, out- or total degree of the specified vertices.

Arguments:

 `graph`: The graph. `res`: Vector, this will contain the result. It should be initialized and will be resized to be the appropriate size. `vids`: Vector, giving the vertex ids of which the degree will be calculated. `mode`: Defines the type of the degree. `IGRAPH_OUT`, out-degree, `IGRAPH_IN`, in-degree, `IGRAPH_ALL`, total degree (sum of the in- and out-degree). This parameter is ignored for undirected graphs. `loops`: Boolean, gives whether the self-loops should be counted.

Returns:

 Error code: `IGRAPH_EINVVID`: invalid vertex id. `IGRAPH_EINVMODE`: invalid mode argument.

Time complexity: O(v) if loops is TRUE, and O(v*d) otherwise. v is the number vertices for which the degree will be calculated, and d is their (average) degree.