Below are the solutions to these exercises on graph theory part-1.

############### # # # Exercise 1 # # # ############### g <- graph.star(n=10, mode = "undirected") plot(g)

############### # # # Exercise 2 # # # ############### g <- add_edges(g, c(8,5, 6,3, 6,10, 5,2, 4,8, 2,7, 6,5, 7,9)) ############### # # # Exercise 3 # # # ############### l = layout_in_circle(g, order = V(g)) plot(g, layout = l)

############### # # # Exercise 4 # # # ############### is.connected(g)

## [1] TRUE

############### # # # Exercise 5 # # # ############### is.bipartite(g)

## [1] FALSE

print("The graph is not bipartite, as there is no possible way to split the vertices into two sets, such that each edge has one endpoint in each set")

## [1] "The graph is not bipartite, as there is no possible way to split the vertices into two sets, such that each edge has one endpoint in each set"

############### # # # Exercise 6 # # # ############### avg.degree <- 2*ecount(g)/vcount(g) ############### # # # Exercise 7 # # # ############### diameter(g)

## [1] 2

############### # # # Exercise 8 # # # ############### sapply(maximal.cliques(g), length)

## [1] 3 3 3 3 3 3 3 3

############### # # # Exercise 9 # # # ############### plot(g, vertex.size = closeness(g)*500)

################ # # # Exercise 10 # # # ################ V(g)$color <- ifelse(V(g)%%2 == 0, "blue", "red") plot(g, vertex.size = closeness(g)*500)

## Leave a Reply