#!/usr/local/bin/python3 # Author: Dr. Robert Heckendorn, Computer Science Department, University of Idaho, 2013 from glib import * # create a separate graph version of the digraph using copy and relink graph = deepcopy(digraph) relink(graph) ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## # USE DFS TO MAKE A ISCONNECTED PREDICATE # simple depth first search in a graph or digraph def isconnected(graph) : visit = array(len(graph), False) isconnectedaux(graph, visit, 0) return all(visit) def isconnectedaux(graph, visit, node) : visit[node] = True for n in graph[node] : if visit[n]==False : isconnectedaux(graph, visit, n) print("IS CONNECTED") print(isconnected(graph)) print(isconnected(digraph)) graph.append({0, 6}) print(isconnected(graph)) print(relink(graph)) print(isconnected(graph))