Generate Maze with Kruskal algorithm by Canvas API


Kruskal algorithm

There is a lot of algorithms for maze generation purpose, such as Depth-first search, Prim, Wilson, Aldous-Broder,... But I used Kruskal for nothing.

In the beginning, we have sets of the cell (called forest), each contains just one cell and a set of edges. With each edge, we have two cells neighbored. If these cells in a different forest, merging two forests. If not, just ignore them.

For presentation sets of the cell, we use the Disjoint-set data structure. With the edges, a simple queue is enough.




By: Anh Hao