Neighbours by hand
Training data on a line: x=1 (class A), 2 (A), 3 (B), 6 (B), 7 (A). Classify x=4 with k=1, 3, and 5. How is the tie at the third neighbour handled for k=3?
Distances from 4: x=3 is at distance 1; x=2 and x=6 are at distance 2; x=1 and x=7 are at distance 3. For k=1 the nearest point is x=3, class B, so the prediction is B. For k=3 the nearest is 3, then 2 and 6 tie at distance 2 for the second and third places. Exactly two points are tied for the last two slots, so both are included. The three neighbours are 3, 2, and 6, with votes B, A, B, so the prediction is B. If a tie straddles the cutoff, the result depends on the convention: one implementation includes all distance ties, and another selects enough tied points at random. For k=5 every point votes, A, A, B, B, A, so A wins by 3 votes to 2. The prediction changes from B to A as k grows.