Implementing the Recursive Backtracker Algorithm

Learn how to implement the Recursive Backtracker algorithm in Ruby.

The RecursiveBacktracker class

We’ll use an explicit stack to manage the cells that have been visited. We’ll use an array to represent the stack (which is easy in Ruby, since Ruby’s arrays come preloaded with the standard push and pop stack operators). Let's look at the code below.

Get hands-on with 1200+ tech skills courses.