Skip to content

Commit bf857bb

Browse files
author
Hamid Gasmi
committed
Issue #87 (Finding an Exit from a Maze): solved with a Disjoint Set DS: Rank Heuristic and Path Compression Heuristic
1 parent b194eca commit bf857bb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

3-graph-algorithms/1_graph_decomposition/reachability-disjoint-sets.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ def __init__(self, n, edges):
77
self.rank = [0] * n
88
self.buildDisjointSets(edges)
99

10-
# Time Complexity: O(|E|)
10+
# Time Complexity (Rank Heuristic): O(|E| log|E|)
11+
# Time Complexity (Path Compression): O(|E| log*|E|)
1112
# Space Complexity: O(1)
1213
def buildDisjointSets(self, edges):
1314
for i in range(0, len(edges)):
@@ -53,12 +54,12 @@ def find(self, v):
5354
def reach(edges, n, u, v, solution):
5455

5556
if solution == 3:
56-
# Good job! (Max time used: 0.04/5.00, max memory used: 10145792/536870912.)
57+
# Good job! (Max time used: 0.04/5.00, max memory used: 10055680/536870912.)
5758
aMazeSets = MazeDisjointSetRankHeuristic(n, edges)
5859
return 1 if aMazeSets.find(u) == aMazeSets.find(v) else 0
5960

6061
elif solution == 4:
61-
# Good job! (Time used: 0.04/5.00, memory used: 9732096/536870912.)
62+
# Good job! (Max time used: 0.04/5.00, max memory used: 10031104/536870912.)
6263
aMazeSets = MazeDisjointSetCompressPathHeuristic(n, edges)
6364
return 1 if aMazeSets.find(u) == aMazeSets.find(v) else 0
6465

0 commit comments

Comments
 (0)