Actually, his algorithm would be 'correct', as in giving a correct maze, since it would only add walls to the getDestroyed list if they passes the Union-Find test. Obviously the algorithm would waste time after adding n-1 walls to the getDestroyed list, because for each remaining wall, Union Find would return that the two connected rooms are in the same equivalence class and the algorithm would simply delete them from wallList and continue until all the walls in wallList are gone. Not a fast algorithm, but still correct. |