Counting Dead Ends

Learn to show how the frequency of dead ends compares between algorithms.

Introducing the deadends method

Let’s see how the frequency of dead ends compares between algorithms. We’ll add a method to our Grid class that collects all of the dead-end cells in the entire grid—those with links to only one other cell—and returns them as a list. Then, we can print the size of that list to tell us how many dead ends there are.

Let's modify grid.rb by adding the following code.

Get hands-on with 1200+ tech skills courses.