Problème 1.
Let be an undirected tree (graph is undirected, connected, and has if we count edges and as the same edge). Let . We say that the distance between and , denoted by dist(m,n)
, is the length of the shortest path between and .
P1.1
Show that
An undirected tree has the following properties:
- is connected and acyclic
- A tree with nodes has edges
- In a tree, there is a unique path between any two vertices.
Let and be two arbitrary vertices in the . There exists a unique path from to .
Let the vertices along the path be: . The length of path is , which is the number of edges
Let the vertices along the path be: . Since is an undirected graph, each edge in corresponds to the same edge in . Therefore, length of path is also
dist(m, n)
denotes the shortest path from m to n, and dist(n, m)
denotes the shortest path from n to m. Since there is one unique path between m and n in the tree, both and are shortest paths between m and n, with length
Therefore
P1.2
Prove that there is a unique path without repeated nodes and edges from node to node with length
dist(m,n)
Since is an undirected tree, there is a unique path between any two vertices. Let and be two arbitrary vertices in the . There exists a simple path from to .
Suppose there are two different simple paths connecting and :
where . Since the paths are different and since is a simple path, must contain an edge that isn’t in
Let the first index for which the edge of is not in . Then .
Let be the first vertex in path after (that is ) that is in the path . Then for some
We now have two simple path, using edges from and using edges from , between and .
The path and have no vertices, edges in common, thus the path from to along followed by the path from to along the reverse of is a cyclic in , which contradicts the assumption that is a tree.
Thus, the path from to is unique simple path
P1.3
Prove the triangle inequality
Let be three arbitrary vertices in the undirected tree a
There exists a simple unique path from to (length is ), a simple unique path from to (length is ).
Consider formed by concatenating and . This is a path from to that passes through (length is )
since denotes path from to , and denotes the shortest path between and , we have
P1.4
Provide an algorithm that computes the distance that is the maximum distance between any pair of nodes in in