```
In [1]:
```import networkx as nx
%matplotlib inline
import pylab
pylab.rcParams['figure.figsize'] = (10.0, 8.0)
import numpy as np
import matplotlib.pyplot as plt
from __future__ import division

**E4.1 Erdös Renyí connectivity**

a) Up to a moderately high number of n (n = 100 should be enough, why not more nodes?) create a sufficiently high number of Erd ̋os-R ́enyi-graphs (around 1000 should be ok).

b) Investigate how many connected components each of these graphs has and average over all graphs for a given n.

c) Plot the average number of connected components over n. Does the behaviour of the number of connected components support the above statement? How long does it take to create an Erd ̋os-R ́enyi-Graph of size n?

**E4.2 Scale free degre distribution**

**a)** Create a Barabasi-Albert random graph with $|V|>500$ and plot the degree distribution using **plt.hist** or **np.histogram**.

**b)** Find out what kind of function fits the degree distribution best. (*Hint: Try semi/doubly logarithmic plots*)

**E4.3 Average shortest path length scaling: small world**

**a)** networkx provides these two functions to generate radom graphs:

- nx.erdos_renyi_graph(nnode, p)
- nx.barabasi_albert_graph(nnode, m)

Find out how the number of edges scales with $p$ and $m$ in these cases respectively.

**b)** Write a function that generates one Erdos-Renyi graph and one Barabasi-Albert graph with $N$ nodes and (approximately) $6N$ edges. Vary $N$ in about 10 stepsizes between 100 and 500. Check which random graph has smalles average shortest path length: Erdos-Renyi or Barabasi-Albert.

**E4.4 Robustness of graphs against attacks**

**E4.3 (b)**, check how many nodes when removed randomly from ER graph and BA graph with similar size and order to make the graph disconnected. Make a remark about which kind of graph is more robust against random attacks aginst nodes.

```
In [ ]:
```