r/programmingchallenges • u/aveganzombie • Sep 09 '11
Make a perfect maze.
A perfect maze is one that has one and only one path between any two points in it (without backtracking).
There are quite a few algorithms out there for this, but trying to make your own is good fun.
29
Upvotes
View all comments
Show parent comment
3
u/HigherFive Sep 10 '11
On line 35 you have
If you change that to
(Python's "=" operator returns the value it assigns, right?) the amortized cost of getParent and union goes down from O(log(n)) to O(log* (n)), which is as close to constant time as you can get.
Also shouldn't the class be named "Section" or "Corridor" rather than "Square"? :P