import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
n_nodes = 50
n_edges = 150
sf_graph = nx.barabasi_albert_graph(n_nodes, int(n_edges / n_nodes))
random_graph = nx.gnm_random_graph(n_nodes, n_edges)
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
nx.draw(sf_graph, with_labels=True, node_size=100, node_color='skyblue', font_size=8)
plt.title("Scale-Free Network")
plt.subplot(1, 2, 2)
nx.draw(random_graph, with_labels=True, node_size=100, node_color='lightcoral', font_size=8)
plt.title("Random Network")
plt.tight_layout()
plt.show()
sf_degrees = dict(sf_graph.degree())
random_degrees = dict(random_graph.degree())
sf_degree_values = list(sf_degrees.values())
random_degree_values = list(random_degrees.values())
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.hist(sf_degree_values, bins=10, color='skyblue', edgecolor='black')
plt.title("Scale-Free Network Degree Distribution")
plt.xlabel("Degree")
plt.ylabel("Frequency")
plt.subplot(1, 2, 2)
plt.hist(random_degree_values, bins=10, color='lightcoral', edgecolor='black')
plt.title("Random Network Degree Distribution")
plt.xlabel("Degree")
plt.ylabel("Frequency")
plt.tight_layout()
plt.show()