aboutsummaryrefslogtreecommitdiff
path: root/final/connectedness/dfs.py
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-11-11 20:58:23 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-11-11 20:58:23 -0500
commit030fb928eeda3256c5e1243584511cc12230eb54 (patch)
treebb487166070d0b11f5595c8475bdebd914d5522c /final/connectedness/dfs.py
parentd378c055cfb3317f0bfbb4f21255e881d9ee2f74 (diff)
parent8c5df53fa24f117311a7a3da4553e0b245ec1b56 (diff)
Merge branch 'master' of https://github.com/feynmansfedora/appcomb-proj
Diffstat (limited to 'final/connectedness/dfs.py')
-rw-r--r--final/connectedness/dfs.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/final/connectedness/dfs.py b/final/connectedness/dfs.py
new file mode 100644
index 0000000..609ddf6
--- /dev/null
+++ b/final/connectedness/dfs.py
@@ -0,0 +1,33 @@
+import networkx as nx
+import numpy as np
+import time
+
+from matplotlib import pyplot as plt
+
+def is_graph_connected(G):
+ VISITED = []
+ def dfs_connectedness(v):
+ nonlocal VISITED
+ for node in G.adj[v].keys():
+ if node not in VISITED:
+ VISITED.append(node)
+ dfs_connectedness(node)
+ return len(VISITED) == len(G.nodes)
+ return dfs_connectedness(0)
+
+x = np.zeros(400)
+y = np.zeros(400)
+for n in range(1, 400):
+ c = 0
+ for _ in range(5):
+ graph = nx.random_geometric_graph(n, 0.125)
+ x[n] = len(graph.nodes) + len(graph.edges)
+ start = time.time()
+ is_graph_connected(graph)
+ c += time.time() - start
+ c /= 5
+ y[n] = c
+ print(n)
+
+plt.scatter(x, y)
+plt.show()