O'Reilly logo

Mazes for Programmers by Jamis Buck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cost versus Distance

images/weighted.png

Imagine traversing a maze, and you come to a branch in the passage. Both paths loop around and meet up again a short distance later, but the passage to the left is blocked by a pool of molten lava. The passage to the right has no lava but is much longer than the other. Which path will get you to the exit faster?

Well, it depends, of course. But for normal people with no special lava resistance, taking the path without the lava is probably going to be optimal, even though it’s longer. The path with the lava, though shorter, is more expensive.

Costs like these are called weights. Distance itself is a form of weight, because ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required