Question 4
library(igraph)
g = graph_from_literal(1-2, 2-3, 3-1, 1---6, 3-1, 2---5, 3-4, 4-5, 4-6, 5-8, 6-7, 7-8)
V(g)$color=c('yellow')
plot(g, layout = layout_with_mds)
Question 4b
as_adjacency_matrix(g)
8 x 8 sparse Matrix of class "dgCMatrix"
1 2 3 6 5 4 8 7
1 . 1 1 1 . . . .
2 1 . 1 . 1 . . .
3 1 1 . . . 1 . .
6 1 . . . . 1 . 1
5 . 1 . . . 1 1 .
4 . . 1 1 1 . . .
8 . . . . 1 . . 1
7 . . . 1 . . 1 .
Question 4c
cat("Density", edge_density(g))
Density 0.3928571
Question 4d
#Complete Network
complete = make_full_graph(8, directed=FALSE)
#Ring Network
ring = make_ring(8, directed = FALSE)
par(mfrow=c(1, 2))
plot(complete)
plot(ring)
cat("Density of Complete Network", edge_density(complete))
Density of Complete Network 1
cat(", Density of Ring Network", edge_density(ring))
, Density of Ring Network 0.2857143
The density of the complete network is bigger than the density of the network in Figure 2, while the density of the ring network is smaller than the density of the network in Figure 2.