A simple approach would be to keep randomly selecting and removing sets of n
nodes until you found a set that doesn't increase the number of components of the graph:
remove.edges <- function(g, n) {
num.tries <- 0
while (TRUE) {
num.tries <- num.tries + 1
g2 <- delete.edges(g, E(g)[sample(seq_along(E(g)), n)])
if (no.clusters(g2) == no.clusters(g)) {
print(paste("Total number of tries:", num.tries))
return(g2)
}
}
}
Let's try it out with a sample graph:
library(igraph)
set.seed(144)
g <- erdos.renyi.game(10, 0.4)
g2 <- remove.edges(g, 5)
# [1] "Total number of tries: 3"
This could be terribly inefficient for a large, sparse graph coupled with a large n
value. In that case, you'll probably want to run something like Tarjan's Bridge-Finding Algorithm at each iteration and limit your random selections to not be bridges. Unfortunately, I can't find an implementation of that algorithm in R, so you'd probably need to do some implementation to get that to work.