Crea funciones para tus algoritmos BFS y DFS
BFS <- function(graph, start) { visited <- c() queue <- c(start) while (length(queue) > 0) { vertex <- queue[1] queue <- queue[-1] if (!(vertex %in% visited)) { visited <- c(visited, vertex) neighbors <- neighbors(graph, vertex) for (neighbor in neighbors) { if (!(neighbor %in% queue)) { queue <- c(queue, neighbor) } } } } return(visited) }