Do edge weights always have to be positive numbers?


#1

Question

In the context of this exercise, do edge weights always have to be positive numbers?

Answer

No, edge weights do not always have to be positive values. They can be positive, negative, or even 0. Edge weights also do not have to be just whole numbers, and can be float values, like 3.5.

For instance, say that a graph is modeling a board game map, where each edge represents a quest and has a weight that associates to how much gold you gain from it. Some quests can cause you to lose gold, where the edges would have a negative weight associated with them.