A maze can be searched in two classic ways: breadth-first, which tries every cell one step away, then every cell two steps away, and so on; or depth-first, which follows one corridor as far as it goes before backing up. Watch both work through the same maze side by side, see that the only difference between them is whether they keep their to-do list as a queue or as a stack, and find out which one is guaranteed the shortest way out.
This article and its interactive demo were created with the help of generative AI and editorially reviewed.
