aboutsummaryrefslogtreecommitdiff
path: root/final/connectedness/dfs.py
diff options
context:
space:
mode:
authorholden watson <holdenew@gmail.com>2019-11-11 21:49:44 -0500
committerholden watson <holdenew@gmail.com>2019-11-11 21:49:44 -0500
commit399fbca52880871a9a927677275ba754d2874c04 (patch)
treef522a29bb464619af1773d600e29ecdbf1b07ad8 /final/connectedness/dfs.py
parent8c5df53fa24f117311a7a3da4553e0b245ec1b56 (diff)
Added more algorithms
Diffstat (limited to 'final/connectedness/dfs.py')
-rw-r--r--final/connectedness/dfs.py33
1 files changed, 18 insertions, 15 deletions
diff --git a/final/connectedness/dfs.py b/final/connectedness/dfs.py
index 609ddf6..00e14ee 100644
--- a/final/connectedness/dfs.py
+++ b/final/connectedness/dfs.py
@@ -15,19 +15,22 @@ def is_graph_connected(G):
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)
+def main():
+ 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
-plt.scatter(x, y)
-plt.show()
+ plt.scatter(x, y)
+ plt.show()
+
+if __name__ == "__main__":
+ main()