I have a pathfinding project and I want to use Kruskal's algorithm as a maze generator. I am using a rank-based disjoint set data structure to detect cycles, which seems to be the standard way.
However, the mazes that I generate cannot be solved. Which leads me to think that there might be something wrong with my implementation logic.
init_walls() //m by n grid of walls
MST = {}
add each node to MST
while MST is not empty
node = random_node()
neighborNode = random_neighbor(node) //up, down, left or right
if find(node) not equal to find(neighborNode)
convertWallToPassage(neighborNode)
union(node, neighborNode)
delete node from MST
find and union are standard operations in the disjoint set used to detect cycles. If two nodes have the same parent, then they are in the same set and hence forms a cycle. I wonder if there is a gap in my logic, or is my approach flawed?