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:

  1. is connected and acyclic
  2. A tree with nodes has edges
  3. 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

Algorithm 34 Maximum Distance in Tree

1:procedure MaxDistance(G\mathcal{G})

2:uu \gets BFS(G,v\mathcal{G}, v)//vv is any arbitrary node in N\mathcal{N}

3:dd \gets BFS(G,u\mathcal{G}, u)

4:

5:return dd

6:end procedure

7:procedure BFS(G,s\mathcal{G}, s)

8:QQ \gets empty queue

9:dist[v]\text{dist}[v] \gets \infty for all vNv \in \mathcal{N}

10:dist[s]0\text{dist}[s] \gets 0

11:Q.Enqueue(s)Q.\text{Enqueue}(s)

12:fsf \gets s

13:while QQ is not empty do

14:uQ.Dequeue()u \gets Q.\text{Dequeue}()

15:fuf \gets u

16:for all vNv \in \mathcal{N} such that (u,v)E(u, v) \in \mathcal{E} do

17:if dist[v]=\text{dist}[v] = \infty then

18:dist[v]dist[u]+1\text{dist}[v] \gets \text{dist}[u] + 1

19:Q.Enqueue(v)Q.\text{Enqueue}(v)

20:end if

21:end for

22:end while

23:

24:return ff

25:end procedure