How can I correctly draw Complete 5-Vertex Undirected Graph that satisfies Triangle Inequality

StackOverflow https://stackoverflow.com/questions/23417018

  •  13-07-2023
  •  | 
  •  

Question

How do I, other than brute forcing, efficiently draw a correct Complete 5-Vertex Undirected Graph with distinct edge weights {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} that satisfies the Triangle inequality? I'm unaware of any algorithm that exists to generate a correct graph G for the edge weights provided.

Here's an example of a Complete 5-Vertex Graph

Was it helpful?

Solution

Here's one that works.

(2,1):  1
(3,1):  2
(3,2):  3
(4,1):  4
(4,2):  5
(4,3):  6
(5,1):  7
(5,2):  8
(5,3):  9
(5,4): 10

The generalization to an n-vertex complete graph should be clear. The proof of correctness is inductive. For n = 0, it's obvious. For higher n, the inductive hypothesis is equivalent to the proposition that every violation of the triangle inequality involves vertex n. The edges involving vertex n are longer than the others, so n is not the transit vertex of a violation. Thus every hypothetical violation (up to symmetry) looks like n -> v -> w. There exists some constant c such that n -> v has length c + v and n -> w has length c + w. Hence, if v -> w is a violation, then it has length less than w - v, which, by inspection, is impossible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top