### 2.1. Graph Constructors and Destructors

2.1.1. `igraph_empty` — Creates an empty graph with some vertices and no edges.
2.1.2. `igraph_empty_attrs` — Creates an empty graph with some vertices, no edges and some graph attributes.
2.1.3. `igraph_copy` — Creates an exact (deep) copy of a graph.
2.1.4. `igraph_destroy` — Frees the memory allocated for a graph object.

#### 2.1.1. `igraph_empty` — Creates an empty graph with some vertices and no edges.

```int igraph_empty(igraph_t *graph, igraph_integer_t n, igraph_bool_t directed);
```

The most basic constructor, all the other constructors should call this to create a minimal graph object.

Arguments:

 `graph`: Pointer to a not-yet initialized graph object. `n`: The number of vertices in the graph, a non-negative integer number is expected. `directed`: Whether the graph is directed or not.

Returns:

 Error code: `IGRAPH_EINVAL`: invalid number of vertices.

Time complexity: O(|V|) for a graph with |V| vertices (and no edges).

#### 2.1.2. `igraph_empty_attrs` — Creates an empty graph with some vertices, no edges and some graph attributes.

```int igraph_empty_attrs(igraph_t *graph, igraph_integer_t n, igraph_bool_t directed, void* attr);
```

Use this instead of `igraph_empty()` if you wish to add some graph attributes right after initialization. This function is currently not very interesting for the ordinary user, just supply 0 here or use `igraph_empty()`.

Arguments:

 `graph`: Pointer to a not-yet initialized graph object. `n`: The number of vertices in the graph, a non-negative integer number is expected. `directed`: Whether the graph is directed or not. `attr`: The attributes.

Returns:

 Error code: `IGRAPH_EINVAL`: invalid number of vertices.

Time complexity: O(|V|) for a graph with |V| vertices (and no edges).

#### 2.1.3. `igraph_copy` — Creates an exact (deep) copy of a graph.

```int igraph_copy(igraph_t *to, const igraph_t *from);
```

This function deeply copies a graph object to create an exact replica of it. The new replica should be destroyed by calling `igraph_destroy()` on it when not needed any more.

You can also create a shallow copy of a graph by simply using the standard assignment operator, but be careful and do not destroy a shallow replica. To avoid this mistake creating shallow copies is not recommended.

Arguments:

 `to`: Pointer to an uninitialized graph object. `from`: Pointer to the graph object to copy.

Returns:

 Error code.

Time complexity: O(|V|+|E|) for a graph with |V| vertices and |E| edges.

#### 2.1.4. `igraph_destroy` — Frees the memory allocated for a graph object.

```int igraph_destroy(igraph_t *graph);
```

This function should be called for every graph object exactly once.

This function invalidates all iterators (of course), but the iterators of are graph should be destroyed before the graph itself anyway.

Arguments:

 `graph`: Pointer to the graph to free.

Returns:

 Error code.

Time complexity: operating system specific.