File tree 1 file changed +31
-1
lines changed
1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
1
from collections import deque
2
2
import random as rand
3
3
import math as math
4
+ import time
4
5
5
6
# the dfault weight is 1 if not assigend but all the implementation is weighted
6
7
@@ -19,7 +20,10 @@ class DirectedGraph:
19
20
self.graph[u] = [[w, v]]
20
21
if not self.graph.get(v):
21
22
self.graph[v] = []
22
-
23
+
24
+ def all_nodes(self):
25
+ return list(self.graph)
26
+
23
27
# handels if the input does not exist
24
28
def remove_pair(self, u, v):
25
29
if self.graph.get(u):
@@ -234,6 +238,18 @@ class DirectedGraph:
234
238
if len(stack) == 0:
235
239
return False
236
240
241
+ def dfs_time(self, s = -2, e = -1):
242
+ begin = time.time()
243
+ self.dfs(s,e)
244
+ end = time.time()
245
+ return end - begin
246
+
247
+ def bfs_time(self, s = -2):
248
+ begin = time.time()
249
+ self.bfs(s)
250
+ end = time.time()
251
+ return end - begin
252
+
237
253
class Graph:
238
254
def __init__(self):
239
255
self.graph = {}
@@ -436,3 +452,17 @@ class Graph:
436
452
# check if se have reached the starting point
437
453
if len(stack) == 0:
438
454
return False
455
+ def all_nodes(self):
456
+ return list(self.graph)
457
+
458
+ def dfs_time(self, s = -2, e = -1):
459
+ begin = time.time()
460
+ self.dfs(s,e)
461
+ end = time.time()
462
+ return end - begin
463
+
464
+ def bfs_time(self, s = -2):
465
+ begin = time.time()
466
+ self.bfs(s)
467
+ end = time.time()
468
+ return end - begin
You can’t perform that action at this time.
0 commit comments