Is it possible to avoid ties entirely?



In this exercise, it explains that ties can occur in the classifications. Is it possible to avoid ties entirely?


No, unfortunately, ties cannot be avoided entirely. To account for this fact, we implement ways to “break” a tie, like choosing one at random or several other methods.

In very few specific cases, they might be avoidable. For instance, for the movie classification, there are only two classifications: “good” or “bad”. If we choose an odd value for k, then ties will never occur, since it cannot have exactly half “good” and half “bad” neighbors. One will have an odd number and the other, an even number, never causing a tie.

In general, for more than two classifications of a dataset, ties are almost impossible to avoid entirely. For example, say that there are three classifications: “A”, “B”, or “C”. No matter what value of k, greater than 1, that we choose, ties can happen. If we choose an even k, like 8, then it might end up as

["A", "A", "A", "A", "B", "B", "B", "B"]

with a tie between “A” and “B”.

Or, if we choose an odd k, say 7, then it might end up as

["A", "B", "B", "B", "C", "C", "C"]

As you can see, we still get a tie, but this time with “B” and “C”.