Next Article in Journal
Two-Threshold-Variable Integer-Valued Autoregressive Model
Previous Article in Journal
Suppression of Fading Noise in Satellite-Mediated Continuous-Variable Quantum Key Distribution via Clusterization
Previous Article in Special Issue
On 2-Rainbow Domination of Generalized Petersen Graphs P(ck,k)
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Modified and Improved Algorithm for Finding a Median Path with a Specific Length () for a Tree Network

1
Department of Mathematics & Computer Science, Faculty of Science, Alexandria University, Alexandria 21544, Egypt
2
Applied Mathematics and Information Science Department, Zewail City of Science and Technology, Giza 12573, Egypt
3
Educational Research and Development Center Sanaa, Sanaa 31220, Yemen
*
Author to whom correspondence should be addressed.
Mathematics 2023, 11(16), 3585; https://doi.org/10.3390/math11163585
Submission received: 29 June 2023 / Revised: 12 August 2023 / Accepted: 14 August 2023 / Published: 18 August 2023

Abstract

:
The median path problem (min-sum criterion) is a common problem in graph theory and tree networks. This problem is open to study because its applications are growing and extending in different fields, such as providing insight for decision-makers when selecting the optimal location for non-emergency services, including railroad lines, highways, pipelines, and transit routes. Also, the min-sum criterion can deal with several networks in different applications. The location problem has traditionally been concerned with the optimal location of a single-point facility at either a vertex or along an edge in a network. Recently, numerous investigators have investigated this classic problem and have studied the location of many facilities, such as paths, trees, and cycles. The concept of the median, which measures the centrality of a vertex in a graph, is extended to the paths in a graph. In this paper, we consider the problem of locating path-shaped facilities on a tree network. A new modified and improved algorithm for finding a median single path facility of a specified length in a tree network is proposed. The median criterion for optimality considers the sum of the distances from all vertices of the tree to the path facility. This problem under the median criterion is called the -core problem. The distance between any two vertices in the tree is equal to the length of the unique path connecting them. This location problem usually has applications in distributed database systems, pipelines, the design of public transportation routes, and communication networks.

1. Introduction

Graph theory began in 1736 with Euler’s work, in which he solved the Konigsberg bridge problem [1]. It is noticeable that in the last half of the twentieth century, research improved in terms of both operational research and discrete mathematics thanks to the computer revolution and the development of computer uses [2].
The terms graph, network, and tree are closely related to algebra. The term network is used in concrete settings, for example, a computer network, a network of friends, social networks, and social networking sites [3,4].
Trees will certainly make us think about what we see in our backyards, parks, and forests, but also about genealogical trees.
In fact, graphs, networks, and trees are very important concepts in computer science. Also, they are important branches of mathematics in the study of graph theory.
The expressions network and graph are mostly used mutually. Work networks are used more often in concrete applications, and a graph is often seen as the abstract representation of a network. For example, in computer networks and social networks, we can see how they share some common notions.
Modern mathematical techniques and powerful computers have played an important role in spreading the use of social networks in many disciplines, such as economics, biology, engineering, and informatics [1,5,6].
Location theory is considered an important domain in operations research. Classical location theory is concerned with finding the optimal location of a set of points on a given network. One of the important location problems for more than one facility is the p-median problem.
A well-known facility location problem in a general network is the p-median problem. Consider a connected and directed network. This median-path problem is relevant to many applications, as studied by several researchers. For example, Avella et al. [7] presented an algorithm to deal with the median-path problem that has arisen in the design of bus and underground train routes in a mass transportation system.
The target of this study was to find the optimal location of a subset of nodes, i.e., facilities, on a network, e.g., the optimal paths of underground trains, overground trains, and trams.
In this paper, we consider that the network is an unweighted tree, and the relationships between its nodes are unidirectional, either up or down, from the root to the leaves.
We assume that this tree represents a graph of a city and its vertices are centers (facilities) in the city, i.e., the area of application of this study is how a public transportation path can be specified to serve the maximum possible number of facilities in a huge city.
In general, this paper concerns the problem of locating a path- or tree-shaped facility on a network. Namely, we aim to find the best path P in the tree T r that minimizes the sum of the distance from the path P to all vertices in T r .
Network models are a very important type of mathematical program that have several practical applications.
Path planning has attracted the attention of many authors, who have proposed several algorithms depending on this concept, e.g., for unmanned aerial vehicles (UAVs). See [8,9,10,11].
Many network problems can be solved by linear programming, and, in fact, special extremely fast variants of linear programming can be applied. This study focuses on problems in which the facilities are path-shaped and the minisum criterion is applied. This field of study has been interesting to researchers past and present. Thus, we provide a comprehensive survey of some previous literature. Several applications require the location of a path-shaped facility instead of a single point or a set of points. For example, the location of pipelines and express lanes in a highway and the design of public transportation routes can be regarded as the location of path-shaped facilities. These problems are NP-hard on general networks, while they are polynomially solvable on tree networks [12].
The core of a tree is defined as a path that is optimal with respect to the property of minimizing the sum of the distances from each vertex in the tree to the path. Richey [13] presented a linear time algorithm for finding the core of a tree network of equal arc lengths. Also, he showed how this algorithm could be extended when there are different arc lengths.
Becker [14] presented a linear time algorithm for finding a minisum path of a tree. He also presented a general bottom-up and top-down procedure that was outlined with several examples. Motevalli et al. [15] presented a study for finding the ( k , ) -core problem on a tree network whose vertices have positive or negative weights. The ( k , ) -core of the T is a subtree with at most k leaves and with a diameter of at most l, where the sum of the weighted distances from all vertices to this subtree is minimized. They showed that, when the sum of the weights of the vertices is negative, the ( k , ) -core must be a single vertex. They proposed an algorithm with a time complexity of O ( n 2 l o g n ) for finding the ( k ; ) -core of a tree with positive or negative weight.
Ashkezari and Fathali [16] presented an algorithm for finding the 2-( ( k ; ) )-core of a tree with a pos-neg weight.
Also, they indicated that in the case when the sum of weights of a tree is negative, the solution of 2- ( k , ) -core is also -median. Therefore, the authors of [16] have stated some properties in a case a tree has a positive weight. Moreover, they presented a polynomial algorithm to find a solution to this problem.
Tamir [17] improved the complexity bound of the p-median problem on the tree networks by showing that the total running time of the “leaves to root” dynamic programming algorithm is O ( p n 2 ) .
Dankelmann and Osaye [18] presented upper bounds on the average eccentricity of the graphs in terms of order and either k-packing number, k-domination number, or connected k-domination number.
Wang et al. [19] presented two efficient algorithms for finding a ( k , ) -tree core of the T.
The time complexity of the first algorithm is O ( n 2 ) when the edge is an arbitrary length, and the second algorithm has O ( k n ) time complexity for the case that the lengths of all edges are equal to 1.
Moshtagh et al. [20] developed two algorithms for finding the optimal path on a tree network along with the queues.
The above brief survey of the previous literature motivates us to present the following contributions in this paper.
  • Suggesting a new approach to re-orientate the directed path on a rooted tree network ( T r ).
  • Adaptation and modification of Dijkstra’s algorithm for computing the distances between the vertices on the tree network and the number of vertices on each subtree.
  • Design two algorithms that will be applied to compute the optimal distances in both upper and lower subtrees.
  • Combining all presented algorithms in this study to obtain a new modified and improved algorithm for finding a core of length of a tree network.
The rest of this paper is organized as follows. In the next section, some of the notations and definitions with a problem description are presented. Section 3 gives a new approach to re-orientate the directed path on a rooted tree network. Section 4 presents some parameters, definitions and functions to obtain a modified and improved algorithm. Numerical results, complexity of time and some examples of practical networks are presented in Section 5. In Section 6, the conclusion and further work are presented.

2. Notation and Definitions with Problem Description

According to the approach mentioned in [13,14,17,21,22,23,24], we present a new similar one with some major modifications and improvements that make the new approach more clear and easy to use. This approach depends on the idea of deleting each edge of a tree network to obtain two subtrees. The lower subtree is rooted at the head vertex of the deleted edge and the upper subtree is rooted at the tail vertex of the deleted edge and then a path with minisum in both subtrees is found.
Therefore, the median path that we intend to find is a combined path of the optimal piece path in the upper subtree with another piece path in the lower subtree so as to make the total length .
Hence the length of the optimal path that is obtained in the upper subtree is < 1 . Also, the length of the optimal path that is obtained in the lower subtree is < 1 .
Thus, the median path is a mingle of the optimal edges in both subtrees beginning at the deleted edge [21].
Definition 1.
Let T = ( V , E ) be a tree network rooted at a vertex r = v V , n = | V ( T r ) | is the number of the vertices in the tree T r and the number of the edges of the tree T r is | E | = n 1 , and let P be a path in the tree T r . The path P consists of sequences of vertices where P T r . The objective is to find the path P, which has the property of minimizing the sum of the distances from all vertices in the tree T r to the nearest vertex in the path P (minisum criterion).
The mathematical formulation of this problem can be described as follows.
min P d ( P ) = v V v P d ( v , P ) .
The lengths of all edges are equal to one.
Solving Problem (1) is to minimize the sum of the distances from the path P to all the vertices of the tree T r [21]. Hence, the optimal maximum saved distance is denoted by the function δ ( d ( r ) , α ) , i.e., it is obtained by the path P. Where d ( r ) = v V v r d ( v , r ) is the sum of the distances from a vertex r to all vertices in the tree T r , α = min ( ψ , μ ) , the parameters ψ and μ are defined by Definition 14 and Formulas (26) and (27), respectively.
In the next sections, we show how the optimal path is selected by implementing n 1 of operations on the entire tree network.
There are several different ways to represent a graph on a computer.
In this paper, a tree network T r is represented in a computer by using two ways, as follows.
Definition 2.
(An adjacency matrix). Let T r be a tree with n vertices that are assumed to be ordered from v 1 = r to v n . The n × n matrix D, which is called an adjacency matrix and defined by
d i j = 1 if a vertex v i parent of a vertex v j , 0 otherwise .
Definition 3.
(Edge lists “Family Matrix” ). It is a simple way to represent a tree T r as a list, or array, of n 1 edges and it is called an edge list (FATH). The edge lists could be stored in the computer as
FATH = fa i sn i + 1 n 1 × 2 ,
where a vertex fa i is a parent of vertex sn i + 1 , i = 1 , 2 , , n 1 , when i = 1 , then fa 1 = r .
In general, an edge of the matrix FATH is denoted by fs = ( fa , sn ) .

3. Re-Orientating a Path on a Rooted Tree Network

This approach is used to re-orient a directed path on a rooted tree network T r .
By deleting an edge fs = (fa, sn) of the tree T r , the tree T r is divided into two subtrees, where the first one is rooted at the vertex “sn” and denoted by
Sn sn T r .
The second subtree is rooted at the vertex “fa” and denoted by
Fa fa = T r Sn sn .
In the following, we show how the tree T r is divided into two subtrees Fa fa and Sn sn namely upper and lower subtrees, respectively.
Definition 4.
Let P r = P { v 1 = r , , v k } be a path starting from the root of the tree T r and ending at the vertex v k , where 1 k 2 , = L ( P d ) is the length of the diameter path P d of the tree T r . Then, the orientation of the directed path P r is reversed to be P k = P { v 1 , , v k , r } , i.e., we find for the predecessors of vertex “fa” and then we reverse the orientation of their direction. Algorithm 1 implements this task as follows.
Algorithm 1, reverses the orientation of the directed path P r as follows.
Algorithm 1 For reversing the orientation of the directed path P r in the tree T r
Input:  fath, fath ¯ , set N 1 = | fath ¯ | , N = 1 , and d.▹ Where d is a number of levels in T r , the matrix fath ¯ contains the levels from L 1 to L d , while the matrix fath contains all levels L 0 , L 1 , L d 1 .
1:
Set η = 1 .
2:
for  i = 1 : N 1 do▹ algorithm is running until the levees of fath ¯ are scanned once.
3:
    pick fs i ¯ = ( fa i ¯ , sn i ¯ ) L j fath ¯
4:
    As long as fs i ¯ L j fath ¯ , then we are looking for the predecessor of the vertex fa i ¯ in the levels L j η of the matrix fath respectively as follows: ▹ where j = 1 , , d and η = 1 , , j .
5:
    Set N 2 = | L j η | .
6:
    for  k = 1 : N 2 do▹ where N 2 = | L j η |
7:
        pick fs k = ( fa k , sn k ) L j η fath . ▹ where the edge fs belongs to one of { L j 1 , L j 2 , , L 0 } .
8:
        if  fa i ¯ = = sn k  then
9:
           Set u N sn k and stored into P fa ¯ = { u N } .
10:
           Set fa i ¯ fa k and N = N + 1 .
11:
           if  j 2 & fa i ¯ r  then
12:
               Set η = η + 1 and go to Line 5.
13:
           end if
14:
        end if
15:
        if  fa i ¯ = = r  then
16:
           return re-orientated path P fa ¯ = { u 1 , , u N , r } .▹ i.e., u 1 , u N r .
17:
           Set N = 1 , η = 1 and go to Line 2.
18:
        else
19:
           go to Line 6.
20:
        end if
21:
    end for
22:
end for

The Mechanism of a Run of Algorithm 1

Algorithm 1 is run according to the following scenario: A given tree network T = ( V , E ) is represented as a list of edges denoted by “a family matrix” defined by (3).
The set of edges E is stored in the matrix FATH as levels L 1 , , L d . For example, the L 1 and L 2 denote the first and the second levels of the matrix FATH, respectively. Where the matrix FATH represents the edges that connect to the root r of the tree T r .
Note: the edges of the first level L 1 connect to the root vertex r, while the edges of the last level L d are the last generation of descendants of the root r with leaf vertices, i.e., each edge of the last level L d ends by leaf vertex “sn”, where d is the number of levels of the tree T r .
Thus, the first level L 1 of the matrix FATH will be removed from the FATH and then we obtain a new matrix denoted by fath ¯ = FATH L 1 .
Similarly, the last level L d of the matrix FATH will be deleted, and then we obtain a new matrix denoted by fath = FATH L d . We set N 1 = | fath ¯ | = n ( 1 + | L 1 | ) is a number of edges of the matrix fath ¯ , and N 2 = | fath | = n ( 1 + | L d | ) is a number of edges of the matrix fath.
Thus, Algorithm 1 visits each edge of the matrix fath ¯ only once.
Then, for each iteration i = 1 : N 1 , Algorithm 1 visits 1 k | L j η | edges of the matrix fath, where j = 1 , 2 , , d denotes the set of the indices of the levels, which belong to the matrix fath ¯ and η = 1 , 2 , , j denotes the set of indices of the levels, which belong to the matrix fath.
For example, when we want to delete the first edge of the first level of the matrix fath ¯ , then the first edge is fs 1 ¯ = ( fa 1 ¯ , sn 1 ¯ ) L 1 fath ¯ .
Hence, we look for the predecessor of the vertex fa 1 ¯ in the level L 1 1 = L 0 of the matrix fath, i.e., in the worst case this operation needs | L 0 | iterations and the second edge of the matrix fath ¯ needs | L 0 | 1 iterations.
Thus, the operation continues such that one or more edges of the first level of the matrix fath ¯ need only one iteration. The stopping criterion of this operation is listed in Line 8 of Algorithm 1.
Accordingly, Algorithm 1 has two loops, which are the outer loop that is denoted by i = 1 : N 1 and the inner loop that is denoted by k = 1 : N 2 .
Thus, the inputs of Algorithm 1 contain the following parameters:
fath, fath ¯ , N 1 = | fath ¯ | , N = 1 is the initial index of the targeted path P fa ¯ and d is the number of possible levels in the tree T r .
In Line 1 of Algorithm 1, η = 1 is a counter of the levels of the matrix fath, which will be visited. The outer loop of Algorithm 1 begins at Line 2.
Each edge of the matrix fath ¯ is deleted in Line 3 of Algorithm 1 by which two subtrees lower and upper subtree are obtained. Therefore, the upper subtree Fa fa is created and rooted at the vertex fa i ¯ .
In Line 4, the level in which the edge fs i ¯ belongs is selected, namely that fs i ¯ L j fath ¯ . Hence, we look for the predecessor of the vertex fa i ¯ in the levels L j η of the matrix fath, respectively, where j = 1 , , d and η = 1 , , j , i.e., we pick the levels L j η of the matrix fath in which the vertex fa i ¯ was a son.
In Line 5 of Algorithm 1, we set N 2 = | L j η | that denotes the number of the edges in the level L j η .
In Line 6 of Algorithm 1, the inner loop runs. In Line 7 of Algorithm 1, we pick the edge fs k = ( fa k , sn k ) L j η fath in which it is possible the vertex fa i ¯ is found.
In Lines 8–9 of Algorithm 1, the path P fa ¯ = { u N } is created. In Lines 11–20 of Algorithm 1, some conditions and operations are tested and implemented, respectively. Therefore, if the condition in Line 15 of Algorithm 1 satisfies, the targeted path P fa ¯ = { u 1 , , u N , r } is completed.
To show how Algorithm 1 is run, by using the tree network which is depicted in Figure 1 as follows. The edge fs = ( d , v ) of the tree network T s of Figure 2 is deleted. The subtrees Sn v and Fa d are created. The subtree Sn v is obtained in a very easy way due to the direction of the edges in the subtree Sn v are the same direction of the edges in the original tree T s . The little difficult is to create the subtree Fa v ; because the orientation of the directed path P s = P { s , a , b , h , d } must reverse to be P d = P { d , h , b , a , s } and then the subtree Fa d = T s T v is obtained, i.e, Algorithm 1 is applied to make the path s a b h d become d h b a s . See Figure 2 and Figure 3. So, we obtain the upper subtree Fa d , which is rooted at the vertex d. See Figure 3.

4. Median Path Algorithm

To design the algorithm that finds the median path of a tree network T r , therefore, we give some definitions, parameters, and formulas. Then, a new improved and modified algorithm is presented according to the following subsection.

4.1. Definition of Parameters

The parameters “ | Sn v | ”, d ( sn ) ( fs , 0 ) , d ( fa ) ( fs , 0 ) , “msdsn”, “msdfa”, “ d ( sn ) ”, “d ( fa ) ”, “k(d ( sn ) )”, “k(d ( fa ) )”, “ ψ ( k d ( sn ) ; d (fa) 0 ) ”, “ μ k d ( fa ) ; d ( sn ) 0 ”, “ α ( ψ , μ ) ” and δ = d ( r ) α , will be defined in the following.
Definition 5.
Let | Sn v | be the number of the vertices in the subtree T v , rooted at v, the | Sn v | = | T v | is computed as follows for each v V , then.
| Sn v | = 1 if v Sd , m + 1 otherwise ,
where Sd is the set of leaves, i.e, Sd is the set of the vertices in the tree T r of degree 1 and m is the number of the vertices in the subtree T v that are descendants of the vertex v.
Definition 6.
Let V sn be a set of the vertices in the subtree Sn sn and E sn be a set of the edges in the subtree Sn sn , and d ( sn ) fs , 0 be the sum of the distance from the vertex sn to all vertices in the subtree Sn sn which it is called “distancesum” [25].
It is defined by
d ( sn ) fs , 0 = v V sn d ( v , sn ) , fs E sn .
Definition 7.
Let V fa be a set of vertices in the subtree Fa fa , E fa be the set of the edges in the subtree Fa fa and d ( fa ) fs , 0 be the sum of the distances form the vertex fa to all vertices in the subtree Fa fa , and it is called “distancesum” [25]. The “distancesum” is defined by
d ( fa ) fs , 0 = v V fa d ( v , fa ) .
Dijkstra’s algorithm solves the single-source shortest-paths problem on a weighted, directed graph G = ( V , E ) for the case in which all edge weights are non-negative [26].
The strategy of Dijkstra’s algorithm depends on visiting all reachable vertices from the source. Then we adapt Dijkstra’s algorithm for calculating the values of the | Sn v | , d ( sn ) ( fs , 0 ) and d ( fa ) ( fs , 0 ) , which are defined by Formulas (6)–(8).
Consequently, Algorithms 2 and 3 are designed to calculate the values of the | Sn v | , d ( sn ) ( fs , 0 ) and d ( fa ) ( fs , 0 ) in the two subtrees Sn sn and Fa fa , respectively.
Algorithm 2 Adaptation and modification of Dijkstra’s algorithm to compute | Sn sn | and d ( fa ) ( fs , 0 )
Input:  i = 0 , T r , and fath.
Output:  DSn = fa sn | Sn sn | d ( sn ) ( n 1 ) × 4
1:
for each fs fath ; fs = ( fa , sn ) , set sn=fs(2). do
2:
    delete the edge fs from T r to create the subtree Sn sn .
3:
end for
4:
for each u V ( Sn sn )  do
5:
     d ( u ) .
6:
     color ( u ) = white .
7:
    set Q sn = ( queue with all vertices ) is defined in (9).
8:
end for
9:
we find for the vertex u in Q sn that represents the sn and we set u = sn and d [ u ] = 0 .
10:
sum 0 , the sum of the distances from the vertex “sn” to all reachable vertices in Sn sn .
11:
Num Node 0 , counter of the vertices that are accessible in Sn sn .
12:
while  Q sn do
13:
     u = Extract min ( Q sn ) , select the element of Q sn with the min distance (d ( u ) ).
14:
     color ( u ) = green .
15:
     Num Node = Num Node + 1
16:
    for each v A d j ( u )  do
17:
         color A d j ( u ) = yellow .
18:
        if  d ( v ) > d ( u ) + w ( u , v )  then
19:
            d ( v ) d ( u ) + w ( u , v ) , relaxation step.
20:
            sum = sum + d ( v ) .
21:
        end if
22:
    end for
23:
     color ( u ) = black , the vertex u has been visited.
24:
    deleted the vertex u with its distance (d ( u ) ) from Q sn .
25:
    replace the old value of the d [ v ] by the new value into the Q sn for each v A d j ( u ) .
26:
end while
27:
set d ( sn ) ( fs , 0 ) = sum .
28:
set i = i + 1 and | Sn sn | = Num Node .
29:
store the values of d ( sn ) ( fs , 0 ) and | Sn sn | into DSn = fa sn | Sn sn | d ( sn ) i × 4
30:
return  DSn = fa sn | Sn sn | d ( sn ) ( n 1 ) × 4
Algorithm 3 Adaptation and modification of Dijkstra’s algorithm to compute | Fa fa | and d ( fa ) ( fs , 0 )
Input:  i = 0 , T r , and fath
Output:  DFa = fa sn | Fa fa | d ( fa ) ( n 1 ) × 4
1:
for each fs fath ; fs = ( fa , sn ) , set sn=fs(2). do
2:
    delete the edge fs from T r to create the subtree Fa fa .
3:
end for
4:
for each u V ( Fa fa )  do
5:
     d ( u ) .
6:
     color ( u ) = white .
7:
    set Q fa = ( queue with all vertices ) is defined in (9).
8:
end for
9:
we find for the vertex u in Q fa that represents the “fa” and we set u = fa and d [ u ] = 0 .
10:
sum 0 , the sum of the distances from the vertex “fa” to all reachable vertices in Fa fa .
11:
Num Node 0 , counter of the vertices that are accessible in Fa fa .
12:
while   Q sn do
13:
     u = Extract min ( Q fa ) , select the element of Q fa with the min. distance (d ( u ) ).
14:
     color ( u ) = green .
15:
     Num Node = Num Node + 1
16:
    for each v A d j ( u )  do
17:
         color A d j ( u ) = yellow .
18:
        if  d ( v ) > d ( u ) + w ( u , v )  then
19:
            d ( v ) d ( u ) + w ( u , v ) , relaxation step.
20:
            sum = sum + d ( v ) .
21:
        end if
22:
    end for
23:
     color ( u ) = black , the vertex u has been visited.
24:
    deleted the vertex u with its distance (d ( u ) ) from Q fa .
25:
    replace the old value of the d [ v ] by the new value into the Q fa for each v A d j ( u ) .
26:
end while
27:
set d ( fa ) ( fs , 0 ) = sum .
28:
set i = i + 1 and | Fa sn | = Num Node .
29:
store the values of d ( fa ) ( fs , 0 ) and | Fa fa | into DFa = fa sn | Fa fa | d ( fa ) i × 4
30:
return  DFa = fa sn | Fa fa | d ( fa ) ( n 1 ) × 4
In both Algorithms 2 and 3, the process mechanism of selecting a vertex u depends on the distance d ( u ) of a current vertex to the source. In our case, the source is the vertex “sn” or the vertex “fa”.
We organize this process into three rows at the priority queue Q sn in Matrix (9) and Q fa in Matrix (10). The two matrices Q sn and Q fa are used in Algorithms 2 and 3, respectively. We store all vertices of the two subtrees Sn sn and Fa fa in the first row of the Q sn in (9) and the Q fa in (10), respectively. We list the sum of the distances from each vertex to source in the second row of both Matrices (9) and (10).
Similarly, the third row of Matrices (9) and (10) contains the color of the current vertex, i.e, a current vertex is the vertex that we want to process; it is the vertex u that we will extract from the first row of the Q sn and Q fa according to the value of the distance d ( u ) .
At the beginning, we set d ( u ) = and color ( u ) = white for all vertices in the subtrees Sn sn and Fa fa . These procedures are implemented by Lines 4–8 in both algorithms.
In Line 9 of Algorithm 2, we find the vertex u in Q represents the source “sn” and we set u = sn and d ( u ) = 0 . Similarly, in Line 9 of Algorithm 3, we find the vertex u in Q represents the source “fa” and we set u = fa and d ( u ) = 0 .
Q sn = u d [ u ] color 3 × | Sn sn | .
Q fa = u d [ u ] color 3 × | Fa fa | .
Definition 8.
Let msdsn be the maximum distance saving of a path in the subtree Sn sn starting from the vertex “sn”.
To compute the values of the msdsn, we use two different types of recursive principles in their operation. See [14,21,24,25,27,28].
In the following scenario, we explain how the values of the “msdsn” are calculated.
For each edge fs = ( fa , sn ) T r , where “sn” is the root of the subtree Sn sn as we have illustrated in Section 3 and Figure 2.
Let L s n = { l s n 1 , , l s n φ } be the set of the sons of the vertex sn, where the φ = | L s n | is the number of the elements in the set L s n .
We set z i = ( sn , l s n i ) and i = 1 , , φ , where the l s n i is the i t h son for the vertex sn. We compute the values of the “msdsn” using the following recursive formulas.
msdsn ( fs , ρ ) = max 1 i φ | Sn l s n i | + msdsn ( z i , ρ 1 ) = msdsn ( P sn , w 1 ) ,
where the P sn , w 1 is the path connecting sn and w 1 with length 1 and maximum distance saving.
If deg(sn) 2 , calculated a path with length 1 and the second maximum distance saving using as follows.
msdsn 2 ( fs , ρ ) = max 1 i φ z i P sn , w 1 | Sn l s n i | + msdsn ( z i , ρ 1 ) = msdsn 2 ( P sn , w 2 ) ,
and P sn , w 1 P sn , w 2 = { sn } , where ρ = 1 , , 1 , msdsn ( fs , 0 ) = 0 and the vertices w 1 and w 2 belong to the subtree Sn sn .
The value of the msdsn ( fs , ρ ) represents the largest distance saved by the path P sn , w 1 calculated by (11).
Let c 1 = z η = ( sn , l s n η ) be the first edge in the path P sn , w 1 , where η { 1 , 2 , , φ } .
The value of the msdsn 2 ( fs , ρ ) represents the second largest distance saved by the path P sn , w 2 .
Let c 2 = z τ = ( sn , l s n τ ) be the first edge in the path P sn , w 2 , where τ { 1 , 2 , , φ } { η } .
Hence, the two paths P sn , w 1 and P sn , w 2 of the length ρ 1 , represent the paths with the largest and the second largest distance saving in the subtree Sn sn rooted at the vertex sn.
Note 1: The edge c 1 and the value of the msdsn 2 will be used in the first branch of Formula (16). The computations in Formula (11) are repeated (n-1) times at ρ = 1 .
Note 2: When φ = 0 , i.e, L s n = , then msdsn ( fs , ρ ) = , i.e, sn S d , also, if φ = 1 , then msdsn 2 ( fs , ρ ) = .
In the following example, we show how the above scenario, Formula (11), and Algorithm 4, are used.
Algorithm 4 For finding the maximum distance saving “msdsn” in the subtree Sn sn
Input:  fath, n and ρ .
Output:  MsdSn.
1:
for each fs∈ fath, fs = ( fa , sn )  do
2:
    set sn=fs(2), L s n = { l s n 1 , , l s n φ } is the set of sons of sn.
3:
    calculate φ = | L s n | which is the number of elements in the set L s n .
4:
    set z i = ( sn , l s n i ) , i = 1 , , φ .
5:
    if  φ = = 0  then
6:
        set msdsn ( fs , ρ ) = .
7:
    else
8:
        for each l s n i L s n and i = 1 , , φ  do
9:
           go to Formulas (11) and (12) to calculate the msdsn ( fs , ρ ) and msdsn 2 ( fs , ρ ) respectively.
10:
        end for
11:
        if  φ = = 1  then
12:
           set msdsn 2 ( fs , ρ ) =
13:
        end if
14:
    end if
15:
end for
16:
return  MsdSn = fa sn msdsn ( fs , ρ ) msdsn 2 ( fs , ρ ) ( n 1 ) × 4 .
Given the tree T in Figure 4, which is rooted at a vertex b, by deleting the edge fs = ( W , H ) the tree T b is divided into two subtrees, in this case, the first one is the subtree Sn H , sn = H , and then L s n = { h 1 , h 2 , h 3 , h 4 } , i.e, l s n 1 = h 1 , l s n 2 = h 2 , l s n 3 = h 3 , l s n 4 = h 4 , are the sons of the vertex H and φ = 4 .
msdsn ( fs , ρ ) = max 1 i 4 | l s n i | + msdsn ( z i , ρ 1 ) , ρ = 1 , msdsn ( z i , 0 ) = 0 , | h 1 | = 4 , | h 2 | = 3 , | h 3 | = 5 , | h 4 | = 4 , therefore, msdsn ( ( W , H ) , 1 ) = max { 4 , 3 , 5 , 4 } , hence msdsn ( ( W , H ) , 1 ) = 5 , c 1 = z 3 = ( H , h 3 ) , msdsn 2 ( ( W , H ) , 1 ) = 4 and c 2 = z τ = ( H , h τ ) , where η = 3 and τ { 1 , 4 } .
The rest of the results of the msdsn ( fs , ρ ) for the other edges in the tree T b are listed in Table 1 below. Column 1 in Table 1, Table 2, Table 3, Table 4, Table 5, Table 6, Table 7 and Table 8 gives the edge “fs” under processing. Column 2 of Table 1 denoted by | Sn sn | presents the values of the | Sn sn | that obtained from Formula (6) using Algorithm 2. Columns 3 and 4 denoted by msdsn ( fs , ρ ) and msdsn 2 ( fs , ρ ) include the first and the second largest distance saving obtained by Formulas (11) and (12), respectively. The edge c 2 is listed in Column 5 of Table 1. Columns 6–9 in Table 1 are similar to Columns 3–4. The values of the msdsn ( fs , ρ ) and msdsn 2 ( fs , ρ ) of the edge fs = ( fa , sn ) are stored into the matrix MsdSn that is defined by the following.
MsdSn = fa sn msdsn ( fs , ρ ) msdsn 2 ( fs , ρ ) ( n 1 ) × 4
Definition 9.
Let msdfa be the maximum distance saving of a path of length ρ 1 ; ρ = 1 , 2 , , 1 in the subtree Fa fa .
To compute the maximum distance saving “msdfa” in the subtree Fa fa , we designate two cases as follows.
Case 1: For any edge fs = ( fa , sn ) of a family matrix “fath”, if fa = r , then the values of the msdfa = ( fs , ρ ) can be calculated by Formula (15) below. Since the root r has no father “fa”, i.e, it has no predecessors, but it has one or more sons. So, we cannot use our approach that we have presented in Algorithm 1 which used to create the subtree Fa fa of T r for computing the “msdfa”, so, instead of that, we present the following approach to compute the values of the “msdfa” regorging the root r with its sons and descendants to the leaves of a tree network. This case represents a special case for calculating the values of the msdfa ( fs , ρ ) .
Let L r = { s o n r 1 , , s o n r N } be the set of the sons of the root r, N = | L r | is the number of the elements in the set L r , we set E k = ( r , s o n r k ) and k = 1 , , N is the set of edges linked directly to the root.
M ρ ( r , E k ) = if N = 1 , | Sn sonr k | + msdsn ( E k , ρ 1 ) o t h e r w i s e ,
where ρ = 1 , 2 , , 1 , the values of the msdsn ( E k , ρ ) are calculated by Formula (11) and msdsn ( E k , 0 ) = 0 .
If d e g ( r ) = 1 , and fs = ( r , s o n r 1 ) , then set M ρ ( r , E 1 ) = . Otherwise, d e g ( r ) 2 , then find M ρ ( r , E k ) for each edge with the root r.
Let γ ρ = max 1 k N M ρ ( r , E k ) be the maximum distance saving obtained by attaching a path of the length ρ through the edge E k * in the tree Fa r = T r rooted at r. Also, let ξ ρ = max 1 k N k k * M ρ ( r , E k ) be the second maximum distance saving obtained by attaching a path of the length ρ through one of the edges of E k E k * in the tree Fa r = T r rooted at r.
Therefore, if fs = ( r , sn ) , the values of the msdfa ( fs , ρ ) can be computed as follows.
msdfa ( fs , ρ ) = ξ ρ if fs = E k * , γ ρ if fs E k * , if N = 1 ,
For more clarification on how Formulas (14) and (15) can be applied, we use the tree T b in Figure 4 as follows.
Suppose we are at the vertex r = b on the tree network of Figure 4, and we want to compute the value of the msdfa ( fs , ρ ) as we have shown above.
Since L r = { s o n r 1 , , s o n r N } = { Q , D , A } , N = 3 , this means the s o n r 1 = Q , s o n r 2 = D , s o n r 3 = A , E 1 = ( b , Q ) , E 2 = ( b , D ) and E 3 = ( b , A ) . Accordingly, we have
M ρ ( r , E k ) = | Sn Q | + msdsn ( E 1 , ρ ) , | Sn D | + msdsn ( E 2 , ρ ) , | Sn A | + msdsn ( E 3 , ρ ) .
Because msdsn ( E k , 0 ) = 0 at ρ = 1 , k = 1 , 2 , 3 , | Sn Q | = 11 , | Sn D | = 21 and | Sn A | = 6 , therefore, M ρ = { 11 , 21 , 6 } .
Hence, γ ρ = 21 , ξ ρ = 11 , E k * = E 2 * = ( b , D ) , E k = ( b , s o n r k ) .
Therefore, msdfa ( fs , 1 ) = 21 for fs = ( b , Q ) and fs = ( b , A ) and msdfa ( fs , 1 ) = 11 for fs = ( b , D ) at ρ = 1 .
Similarly, the rest of the results are obtained from the root “b” to the end of the vertices in the tree T b listed in Table 2. The above approach finds two paths of the length ρ of maximum and second maximum distance saving, which are attached at the root node r. Case 2: For all fs fath , fa = fs ( 1 ) and if fa r , the “msdfa” is computed by the following.
First of all, we go to Algorithm 1 for creating the subtree Fa fa . Let gf be a father of the vertex fa we set g=(gf, fa) and fs = ( fa , sn ) , and we compute the values of the “msdfa” by Formula (16).
msdfa ( fs , ρ ) = max π ( fa ) + msdfa ( g , ρ 1 ) , msdsn 2 ( g , ρ ) if fs = = c 1 , max π ( fa ) + msdfa ( g , ρ 1 ) , msdsn ( g , ρ ) otherwise ,
where the value of the π ( fa ) is calculated by the following equation:
π ( fa ) = n | V ( Sn fa ) | ,
where n = | V ( T r ) | is the number of vertices of the tree T r , | V ( Sn fa ) | is the number of vertices in the subtree Sn fa = T fa , it is calculated by Formula (6) and the value of the msdsn 2 ( g , ρ ) is computed by Formula (12).
For example, assume we choose the edge fs = ( W , H ) of the tree network in Figure 4, as we have done above where fa = W and sn = H . So, the subtree Fa W is created by Algorithm 1.
We set fg = D as the father of the vertex W, therefore, g = ( D , W ) .
Now, we compare fs = ( W , H ) with the edges c 1 that are listed in Column 5 of Table 1, i.e, the edges c 1 that we have obtained from Formula (11), when we computed the value of the msdsn ( ( D , W ) , 1 ) = 17 , it is obtained by the edge c 1 = ( W , H ) .
Since, fs = ( W , H ) = c 1 is listed in Line 6 of Column 5 in Table 1 at ρ = 1 , where c 1 is the edge that corresponds the value of the msdsn ( g , 1 ) = 17 and msdsn 2 ( g , 1 ) = .
Therefore, we apply the first branch of Formula (16) as follows: msdfa ( fs , 1 ) = max π ( W ) + msdfa ( g , 0 ) , msdsn 2 ( g , 1 ) , | V ( Sn W ) | = 18 , π ( W ) = 39 18 = 21 , msdfa ( g , 0 ) = 0 , msdsn 2 ( g , 1 ) = .
Therefore, msdfa ( fs , 1 ) = max 21 , = 21 at ρ = 1 .
The rest of the results are in Table 2 below. Columns 2 7 contain the values of the msdfa ( fs , ρ ) , with ρ = 1 , , 1 , that we have obtained from Formulas (15) and (16) and Algorithms 5 and 6.
The results of the “msdfa” that we have obtained from Cases 1 and 2 of Definition 9 are stored in the matrix MsdFa in the following.
MsdFa = fa sn msdfa ( fs , ρ ) ( n 1 ) × 3
Algorithm 5 For finding the maximum distance saving ( msdfa ) in the subtree fa r
Input:  “fath” and n.
Output:  msdfa ( fs , ρ ) = ξ ρ , if fs = E k * and msdfa ( fs , ρ ) = γ ρ if fs E k * .
1:
Let L r = { s o n r 1 , , s o n r N } be the set of sons of the root r.
2:
compute N = | L r | is the number of elements in the set L r .
3:
set E k = ( r , s o n r k ) where k = 1 , , N .
4:
if N = = 1 then
5:
    set msdfa ( fs , ρ ) = .
6:
else
7:
    for each s o n r k L r and k = 1 , , N  do
8:
        go to Formula (15) to compute the values of the γ ρ and ξ ρ .
9:
    end for
10:
end if
11:
return  msdfa ( fs , ρ ) = ξ ρ , if fs = E k * and msdfa ( fs , ρ ) = γ ρ if fs E k * .
Algorithm 6 For finding the maximum distance saving “msdfa” in subtree Fa fa
Input:  fath, n, T r and ρ = 1 , , 1 .
Output:  MsdFa.
1:
for each fs ∈ fath, fs = ( fa , sn ) . do
2:
    set fa = fs ( 1 ) and go to Algorithm 1 to create the subtree Fa fa .
3:
    if  fa r  then
4:
        return to Formula (16) to compute the value of the msdfa ( fs , ρ ) .
5:
    else
6:
        go to Algorithm 5 to compute the value of the msdfa ( fs , ρ ) , where fa = r .
7:
    end if
8:
end for
9:
return  MsdFa = fa sn msdfa ( fs , ρ ) ( n 1 ) × 3
Definition 10.
Suppose, the best path in the subtree Sn sn is defined by the following.
p ρ = p ρ 1 c 1 ,
where ρ = 1 , 2 , , 1 , p 0 = , the edge c 1 E sn is incident to sn contained in the path that gives the value of msds ( fs , ρ ) by Formula (11), and then the sum of the distance form the path p ρ to all vertices in the subtree Sn sn is defined by the following equation.
d ( sn ) fs , σ = d ( sn ) fs , 0 msdsn ( fs , σ ) ,
where σ = 0 , 1 , , 1 , for example, when σ = 0 , msdsn ( fs , 0 ) = 0 , then the d ( sn ) ( fs , 0 ) = d ( sn ) fs , 0 msdsn ( fs , 0 ) , where the term d ( sn ) ( fs , 0 ) is the sum of the distances from the root “sn” of the subtree Sn sn to all vertices in the subtree Sn sn , it is defined by (7).
This means the beginning of the targeted path is attached to the head of the edge fs = ( fa , sn ) .
Hence, Formula (11) is used to find the maximum distance saving obtained by attaching a path of length ρ to the vertex sn. For example, when the edge fs = ( d , v ) is deleted from the tree network T s of Figure 1, we obtain two subtrees; the first one is the subtree Sn v = T v . Hence, the number of adjacent edges of the vertex sn = v are three edges, the optimal edge of them is the edge c 1 = ( v , p ) . See Figure 2. The edge c 1 = ( v , p ) is obtained by Formula (11), in this case, when ρ = 1 and σ = 1 , so the targeted path is p 1 = p 0 c 1 , hence p 1 = c 1 . Therefore, the sum of the distance from the path p 1 to all vertices in the subtree Sn sn equals to d ( sn ) ( fs , 1 ) = d ( sn ) fs , 0 msdsn ( fs , 1 ) .
Similarly, at ρ = 2 and σ = 2 , p 2 = p 1 c 1 , then the “distancesum” of the path p 2 equals to the d ( sn ) fs , 2 = d ( sn ) 0 msdsn ( fs , 2 ) .
For further illustration, we use the tree network depicted in Figure 4 as follows.
Assume we pick the edge fs = ( W , H ) and σ = 0 , then fa = W and sn = H , hence d ( H ) ( fs , 0 ) = 28 . Now, when σ = 1 and ρ = 1 , we have to return to Formula (11) for computing the value of the msdsn ( fs , 1 ) = 5 , and this result is obtained by the edge c 1 = ( H , h 3 ) , and then p 1 = ( H , h 3 ) . Hence, d ( sn ) fs , 1 = 28 5 = 23 , similarly, when σ = 2 and ρ = 2 , therefore, d ( sn ) fs , 2 = 28 6 = 22 , this result has been obtained through the path p 2 = p 1 ( h 3 , ) , finally when σ = 3 and ρ = 3 , therefore, d ( sn ) fs , 3 = 28 ( ) = , there is no edge that gives this result. It means the calculation on the subtree Sn H has finished.
The rest of the results are presented in Table 3. Column 2 of Table 3 denoted by d ( sn ) 0 contains a sequence of the sum of the distances from the vertex “sn” to all vertices in the subtree Sn sn , which are computed by Formula (7) using Algorithm 2, Columns 4 7 of Table 3 show the values of the d ( sn ) σ that we have obtained from Formula (20).
Definition 11.
The best path in the subtree Fa fa can be defined as follows.
In Definition 9, we have used two cases as follows.
According to Formula (14) in Case 1, when fa = r , the best edge of the adjacent edges, which are connected to the root r, is the edge E k * . In this case, the best path in the subtree.
Fa fa is defined by the following.
p ρ = p ρ 1 E k * , ρ = 1 , 2 , 1 , fs E k * .
Now, when ρ = 1 and σ = 1 , the targeted path is p 1 = p 0 E k * , hence p 1 = E k * .
For example, in Figure 1, when we want to compute the value of the msdfa ( fs , ρ ) for the edge fs = ( s , y ) , we delete the edge fs = ( s , y ) of the tree T s , and then we obtain the subtree Fa s = T s Sn y . At σ = 1 and ρ = 1 , the value of the msdfa ( ( s , y ) , 1 ) is calculated by Formula (14), then msdfa ( ( s , y ) , 1 ) = 24 , is obtained by the edge E 1 = ( s , a ) , hence p 1 = ( s , a ) .
In Case 2 of Definition 9, when fa r , the values of the msdfa ( fs , ρ ) are computed by Formula (16), therefore, the best edge is an edge of the predecessor or descendant that is associated with the vertex “fa” without the edge fs = ( fa , sn ) that we have deleted from the tree T r .
Note 1: If the condition in the first branch of Formula (16) satisfies and π ( fa ) + msdfa ( g , ρ 1 ) < msdsn 2 , the value of the msdfa ( fs , ρ ) equals to msdsn 2 .
Note 2: If the condition in the first branch of Formula (16) satisfies and π ( fa ) + msdfa ( g , ρ 1 ) > msdsn 2 , this means that the value of the msdfa ( fs , ρ 1 ) equals to π ( fa ) + msdfa ( g , ρ ) . Accordingly, in Case 2, the best path in the subtree Fa fa is defined by the following.
p ρ = p ρ 1 c 2 if fs = = c 1 and π ( fa ) + msdfa ( g , ρ 1 ) < msdsn 2 , p ρ 1 g otherwise , for ρ = 1 , , 1 ,
where the edge g = ( g f , f a ) is connected directly to the deleted edge fs = (fa, sn) and the c 1 and c 2 are the first and second best edges connected to the deleted edge fs = (fa, sn) according to (11) and (12), respectively.
For example, in Figure 1, when we compute the value of the msdsn ( fs , ρ ) for the edge fs = ( h , d ) , we delete the edge fs = ( h , d ) of the tree T s , and then we obtain the two subtrees Sn d and Fa h .
We return to Formula (11) to compute msdsn ( fs , ρ ) , at ρ = 1 , the msdsn ( ( h , d ) , 1 ) = 11 is obtained by the edge c 1 = ( d , v ) and msdsn 2 = 1 is obtained by the edge c 2 = ( d , τ ) .
Now, when we want to calculate the value of the msdfa ( fs , ρ ) for the edge fs = ( d , v ) . Firstly, we delete edge fs = ( d , v ) of the tree T s , and then we obtain two subtrees, which are Sn v = T v and Fa d = T s T v . According to Formula (16), g = ( fg , fa ) = ( h , d ) , we note that the fs = c 1 = ( d , v ) , then we use the first branch of Formula (16). At ρ = 1 , msdfa ( ( d , v ) , 1 ) = max π ( fa ) + msdfa ( g , 0 ) , msdsn 2 , we compute the value of the π ( fa ) = 34 13 = 21 , by Formula (17), msdfa ( ( d , v ) , 1 ) = max { 21 + 0 , 1 } , i.e, π ( fa ) + msdfa ( ( h , d ) , 0 ) = 21 > msdsn 2 = 1 , therefore, we apply the second branch of Formula (22) to specify the best path in the subtree Fa d , and the best path is p 1 = ( h , d ) .
Therefore, the sum of the distance form the path p ρ to all vertices in the subtree Fa fa is defined in the following equation.
d ( fa ) fs , σ = d ( fa ) fs , 0 msdfa ( fs , σ ) ,
where σ = 0 , 1 , , 1 , for example, when σ = 0 , msdfa ( fs , 0 ) = 0 , then the d ( fa ) ( fs , 0 ) = d ( fa ) fs , 0 msdfa ( fs , 0 ) . The term d ( fa ) ( fs , 0 ) is the sum of the distances from the root “fa” of the subtree Fa fa to all vertices in the subtree Fa fa , according to (8).
This means that the beginning of the targeted path is sitting at the vertex “fa” of the edge fs = ( fa , sn ) , i.e., the best edge is either the predecessor of the vertex “fa” or the descendant of the vertex “fa”.
Hence, Formula (16) will drive the vertex “fa” to the best edge of the subtree Fa fa .
Therefore, the sum of the distance form the path p 1 to all vertices in the subtree Fa fa equals to d ( fa ) ( fs , 1 ) = d ( fa ) fs , 0 msdfa ( fs , 1 ) , where the value of the d ( fa ) fs , 0 is constant for the edge “fs” at σ = 0 , 1 , , 1 , i.e., it represents the initial value of Formula (23) and the value of the msdfa ( fs , 1 ) is calculated by Formula (16). For more illustration, we use the example that we present in Figure 4 by the following.
Assume we pick the edge fs = ( W , H ) and σ = 0 , then fa = W , hence d = 73 , and this value has been computed by Algorithm 3. Now, when σ = 1 and ρ = 1 , d ( W ) ( fs , 1 ) = ( W ) ( fs , 0 ) msdfa ( fs , 1 ) = 73 21 = 52 , where the value of the msdfa ( fs , 1 ) = 21 is calculated by Formula (16), hence this result has been obtained through the edge g = ( D , W ) , and p 1 = ( D , W ) . Similarly, at σ = 2 and ρ = 2 , d ( W ) ( fs , 2 ) = 73 39 = 34 , this result has been obtained through the edge g = ( b , D ) , and p 2 = p 1 ( b , D ) , at σ = 3 and ρ = 3 , d ( W ) ( fs , 3 ) = 73 50 = 23 , and this result has been obtained through the edge g = ( b , Q ) , and p 3 = p 2 ( b , Q ) , at σ = 4 and ρ = 4 , d ( W ) ( fs , 2 ) = 73 51 = 22 , and this result has been obtained through the edge g = ( Q , q i ) , and p 4 = p 3 ( Q , q i ) , where 1 i 10 . Finally, when σ = 5 and ρ = 5 , therefore, d ( fa ) fs , 3 = 73 ( ) = , there is no edge that gives this result. It means the calculation on the subtree fa W has finished.
The rest of the results are presented in Table 4. Column 1 of Table 4 is labeled by d ( fa ) 0 , which contains a sequence of the sum of the distances from the vertex “fa” to all vertices in the subtree Fa fa , which are computed by Formula (8) using Algorithm 3, Columns 4 8 in Table 4 show the values of the d ( fa ) σ that we have obtained from Formula (23).
Definition 12.
Let k d ( sn ) fs , ρ be used to compare the “distancesum” of all paths with d ( sn ) fs , ρ in the subtrees Sn sn for the the edge “fs” of length ρ = 1 , 2 , , 1 , i.e., the value of the k d ( sn ) fs , ρ represents the “distancesum” of a best path of length ρ = 1 , 2 , , 1 in the subtrees Sn sn , that starts from the vertex “sn” to the farthest leaf on the subtree Sn sn . See [21,25]. The k d ( sn ) fs , ρ is defined by the following.
k d ( sn ) ( fs , ρ ) = d ( sn ) ( fs , ρ ) if ρ = 0 , min { d ( sn ) ( fs , ρ ) , k d ( sn ) ( fs , ρ 1 ) } otherwise .
Definition 13.
Let k d ( fa ) fs , ρ be used to keep the “distancesum” at a minimum value of the d ( fa ) fs , ρ in the subtree Fa fa for the the edge “fs” at length ρ = 1 , , 1 .
In other words, the value of the k d ( fa ) fs , ρ is the “distancesum” of a best path of length ρ = 1 , , 1 , that begins from the vertex “fa” to the farthest leaf on the subtree Fa fa .
The k d ( fa ) fs , ρ is defined by
k d ( fa ) ( fs , ρ ) = d ( fa ) ( fs , ρ ) if ρ = 0 , min { d ( fa ) ( fs , ρ ) , k d [ fa ] ( fs , ρ 1 ) } otherwise .
Note 1: In the following, we show how Formulas (24) and (25) are used.
Given, fs = ( W , H ) on the tree network of Figure 4, where sn = H , fa = W , because the value of the d ( H ) ( fs , σ ) equals to 28 at ρ = 0 , therefore, k d ( H ) ( fs , 0 ) = 28 , by using the first branch of Formula (24).
Now, when ρ = 1 , at the same edge fs = ( W , H ) , d ( H ) ( fs , 1 ) = 23 , hence k d ( H ) ( fs , 1 ) = min { 28 , 23 } = 23 , similarly, d ( H ) ( fs , 2 ) = 22 , then k d ( H ) ( fs , 1 ) = min { 23 , 22 } = 22 .
Finally, at ρ = 3 , d ( H ) ( fs , 3 ) = , therefore, k d ( H ) ( fs , 1 ) = min { 22 , } = 22 .
Similarly, for the same edge fs = ( W , H ) regorging to the subtree Fa W , we use Formula (25), then k d [ W ] ( fs , 0 ) = d [ W ] ( fs , 0 ) = 73 , k ( W ) ( fs , 1 ) = min { d [ W ] ( fs , 1 ) ; k d [ W ] ( fs , 0 ) } = min { 52 , 73 } = 52 , k ( W ) ( fs , 2 ) = min { 34 , 52 } = 34 , k ( W ) ( fs , 3 ) = min { 23 , 34 } = 23 , finally, at ρ = 4 , k ( W ) ( fs , 4 ) = min { 22 , 23 } = 22 .
The rest of the results of the k d ( sn ) ( fs , ρ ) and k d ( fa ) ( fs , ρ ) are presented in Table 5 and Table 6, respectively. Column 1 in both Table 5 and Table 6 is labeled by k ( d ( sn ) 0 ) and k ( d ( fa ) 0 ) contains the sum of the distance form both vertices “sn” and “fa” to the all vertices in the subtrees Sn sn and Fa fa that have been obtained by Formulas (24) and (25). The other columns in both tables give the values of the k ( d ( sn ) ρ ) and k ( d ( fa ) ρ ) , which represent the “distancesum” from a path p ρ = p ρ 1 fs to all vertices in the two subtrees Sn sn and Fa fa , with the length ρ 1 , respectively.
In the following we present a mechanism to specify the optimal path on the whole tree.
Definition 14.
Let ψ and μ be two functions by which the best path in the two subtrees Sn sn and Fa fa is combined by picking the best edge of both ( ψ , μ ) to obtain a composite path that represents the median path (ℓ-core) for a tree network with the length ℓ.
These two functions are defined by
ψ ( fs , ρ ) = k d ( sn ) ( fs , ρ 1 ) + d ( fa ) ( fs , 0 ) ,
and
μ ( fs , ρ ) = k d ( fa ) ( fs , ρ 1 ) + d ( sn ) ( fs , 0 ) ,
where ρ = 1 , , 1 , the ψ ( fs , ρ ) denotes the sum of the distance from a candidate path p ρ + 1 = p ρ fs to all vertices in the subtree Sn sn and μ ( fs , ρ + 1 ) denotes the sum of the distance from a candidate path p ρ + 1 = p ρ fs to all vertices in the subtree Fa fa .
For example, at the tree network depicted in Figure 4, if ρ = 1 and the edged is fs = ( b , A ) , then ψ ( fs , 1 ) = k d [ A ] ( fs , ρ ) + d [ b ] ( fs , 0 ) = 107 + 5 = 112 , for fs = ( b , Q ) , ψ ( fs , 1 ) = 97 + 10 = 109 , for fs = ( b , D ) , ψ ( fs , 1 ) = 97 , for fs = ( D , W ) , ψ ( fs , 1 ) = 97 and for fs = ( W , h ) , ψ ( fs , 1 ) = 101 .
The five values of the ψ ( fs , 1 ) = { 112 , 107 , 97 , 97 , 101 } , denote the sum of the distances from each edge of { ( b , A ) , ( b , Q ) , ( b , D ) , ( D , W ) , ( W , H ) } to all vertices in the tree T b , e.g., the ψ ( fs , 1 ) = 112 , denotes the sum of the distances from the edge fs = ( b , A ) to all vertices in the tree T b .
Similarly, there are the five values of the μ ( fs , 1 ) .
According to Problem (1) that describes the optimal path, we find the minimum distance among the set values of the ψ and μ .
We note that the minimum value is 97, that corresponds to either the edge ( b , D ) or ( D , W ) , so the best path with length = 1 is either p 1 = ( D , W ) or p 1 = ( b , D ) . Now, we need to create a path from the both functions ψ and μ that will represent the optimal path in the tree T r .
In general, the optimal path p ρ is selected according to the following formulas:
α ( fs , ρ ) = min { ψ ( fs , ρ ) , μ ( fs , ρ ) } ,
p ρ = p ρ 1 fs ,
where ρ = 1 , , 1 , fs fath , i.e , fs E .
Formula (28) means that the fs edge, which gives the minimum value of the function α ( fs , ρ ) , will be added to the the optimal path defined by Formula (29).
For example, at ρ = 1 , for each fs on the tree T r , we obtain α ( fs , 1 ) = min { ψ ( fs , 1 ) , μ ( fs , 1 ) } .
Hence, the value of the α ( fs , 1 ) , is the minimum sum of the distance from the edge “fs” to all vertices on the tree T r .
Therefore, the optimal path is p 1 = p 0 fs , where the p 0 = ϕ is the initial (empty) path.
Similarly, when ρ = 1 , for each fs on the tree T r we obtain α ( fs , 1 ) = min { ψ ( fs , 2 ) , μ ( fs , 2 ) } .
Hence, the value of the α ( fs , 1 ) represents the minimum sum of the distance form the path p 1 to all vertices on the tree T r . Therefore, the optimal path is p 2 = p 1 fs , and so on up to the required length, i.e., | P | = | p 1 | + | p 2 | + = .
In general, ρ 0 , the value of the α ( fs , ρ ) represents the minimum sum of the distances from the path p ρ + 1 to all vertices on a tree T r network. For further illustration, see Table 7, Table 8 and Table 9, regorging the tree T b in Figure 4.

4.2. Recursive Modified and Improved Algorithm

The modifications and suggestions that are presented in the above sections lead us to design the following recursive modified and improved algorithm as a developed algorithm finds a core for a tree network rooted at a vertex r, with a length equals to .
In the following, we present the main algorithm that achieves this purpose.
Therefore, we have depicted Algorithm 7, in Figure 5.
Algorithm 7 For finding -core of a tree
Output:  P is the optimal path with length .
Input:   fath and dim < 2 dim given by user.
1:
for  ρ 1 to  do
2:
    for each fs∈ fath do
3:
        compute the ψ and the μ by using Formulas (26) and (27).
4:
        compute α = min { ψ , μ } .
5:
        set p ρ + 1 = p ρ fs , where “fs” corresponding the value of α at ρ .
6:
    end for
7:
end for
8:
return  P = p is the optimal path with length .

5. Numerical Results

Some test examples of tree networks are run on a PC with Intel(R) Core(TM) i5-3230M [email protected] 2.60 GHz with RAM 4.00GB of memory on Windows 10 operating system, by utilizing MATLAB version 8.5.0.197613 (R2015a; MathWorks, Inc., Natick, MA, USA).
As we have mentioned, our aim is to find the optimal path on a tree network.

5.1. Time Complexity Analysis

The time complexity of the main algorithm (Algorithm 7) can be computed by the following.
We compute the time complexity of all six algorithms, and then the worst time complexity of these six algorithms represents the time complexity of Algorithm 7.
Since Algorithm 1 visits each edge of the matrix fath ¯ only once, i.e., for each iteration i of N 1 Algorithm 1 visits an edge of the matrix fath 1 k | L j η | time, where j = 1 , 2 , , d denotes the index of the level, which belongs to the matrix fath ¯ and η = 1 , 2 , , j denotes the index of the level, which belongs to the matrix fath.
Accordingly, Algorithm 1, has two loops are the outer loop that denoted by i = 1 : N 1 and the inner loop that denoted by k = 1 : N 2 .
Before we compute the time complexity of Algorithm 1, which has two loops (outer and inner), we present a general example for an algorithm that has two loops (outer and inner loop) (Algorithm 8).
Algorithm 8 General algorithm contains two loops (outer and inner)
1:
for  i = 1 : n do
2:
    Statement
3:
    for  k = 1 : m  do
4:
        Statement 1
5:
        Statement 2
6:
        Statement 3
7:
    end for
8:
end for
We analyze the time complexity of Algorithm 8, as follows: for each i (n times), we iterate over all k (m times), which leads n × m = n m iterations, hence the time complexity of this example is O ( n m ) if m = n , then the time complexity of Algorithm 8, is O ( n 2 ) .
Since Algorithm 1 is similar to Algorithm 8, both algorithms have nested loops (outer and inner loop). But, Algorithm 1 runs in a different way.
We analyze the time complexity of Algorithm 1 as follows: the outer loop of Algorithm 1 is i = 1 : N 1 and the inner loop is k = 1 : N 2 , and if Algorithm 1 runs like Algorithm 8, then the time complexity of Algorithm 1 is O ( N 1 × N 2 ) = O ( n 2 ) , but Algorithm 1 does not work like Algorithm 8.
Assume Algorithm 1 at the first level L 1 fath ¯ , then Algorithm 1 finds for the predecessor of the vertex fa 1 ¯ in the level L 1 1 = L 0 of the matrix fath. Hence, the worst case of i = 1 : | L 1 | is rebated | L 0 | iterations. Also, the worst case of i = 1 : | L 2 | is rebated | L 0 | + | L 1 | iterations in the worst case of i = 1 : | L 3 | is rebated | L 0 | + | L 1 | + | L 2 | iterations in the worst case of i = 1 : | L 4 | is rebated | L 0 | + | L 1 | + | L 2 | + | L 3 | iterations, and so on in the worst case of i = 1 : | L d | is rebated | L 0 | + | L 1 | + | L 2 | + | L 3 | + + | L d 1 | iterations.
In general, the worst case of i = 1 : N 1 is rebated j = 0 d 1 | L j | = N 2 = | fath | = n ( 1 + | L d | ) iterations.
Therefore, for each i = 1 : N 1 cannot be iterated over all k ( N 2 times).
Hence, the running mechanism of Algorithm 1 is less costly compared to the running mechanism of Algorithm 8. Therefore, the time complexity of Algorithm 8 is greater than the time complexity of Algorithm 1.
Therefore, it can be deduced that the time complexity of Algorithm 1 is less than O ( n 2 ) , and greater than O ( n l o g ( n ) , it can be formed as O ( n l o g ( n ) < O ( x x ) < O ( n 2 ) .
Now, we analyze the time complexity of Algorithms 2 and 3 as follows:
The time complexity of Lines 1:3 of Algorithm 2, is O ( n ) and the time complexity of Lines 4:8 of Algorithm 2, is O ( n ) . The time complexity of Lines 16:22 of Algorithm 2 is O ( 1 ) O ( n ) = O ( n ) , hence the time complexity of Lines 12:26 of Algorithm 2 is O ( n ) . Therefore, the time complexity of Algorithm 2 is O ( n ) + O ( n ) + O ( n ) = 3 O ( n ) = O ( n ) . Similarly, the time complexity of Algorithm 3 is O ( n ) .
Now, we analyze the time complexity of Algorithms 4 and 5 as follows:
The time complexity of the outer loop, which begins at Line 1 of Algorithm 4, is n 1 times and the time complexity of the inner loop, which is listed in Lines 8:10 of Algorithm 4, is φ . ( n 1 ) time.
Therefore, the time complexity of Algorithm 4 is O ( n ) time.
While the time complexity of Algorithm 5 is O ( N ) where N < < n .
The time complexity of Algorithm 6 is O ( n 1 ) + O ( N ) = O ( n ) .
Finally, the time complexity of of Algorithm 7 is computed as follows:
Algorithm 7 has two loops (outer and inner loop), where in the outer loop the length (constant) is given an advance that represents the length of the median path that we intend to find, hence the cost of the outer loop is time. The cost of the inner in Algorithm 7 is computed as follows:
The worst of the time complexity of Algorithms 1–6 is O ( x x ) time, where O ( n l o g ( n ) < O ( x x ) < O ( n 2 ) .
Therefore, the time complexity of Algorithm 7 is O ( x x ) .
According to the above discussion, we present the following.
Theorem 1.
Algorithm 7 finds the median path of a tree network with length ℓ in O ( x x ) time, where O ( n l o g ( n ) < O ( x x ) < O ( n 2 ) .
Proof. 
Since the distancesum D ( v ) for each v V can be implemented in O ( n ) time and by using the above results. Then, Algorithm 7 runs in O ( x x ) time where O ( n l o g ( n ) < O ( x x ) < O ( n 2 ) . □

5.2. Examples of Practical Networks

The mathematical modeling process is an important tool used to formulate many applied life problems to be forms of mathematical problems. At the core of every policy or planning decision, there are intended options to obtain one or more outcomes. The field of optimization is concerned with how this process can be quantitatively modeled, and, within the restrictions of these quantitative models, how the best decisions can be made. In other words, it is a science that researches the best solution among many solutions when there exists no exact (known) solution to the problem.
In recent years, the problem of finding the optimal locations of servers on an operating network as a given tree network. See for example [20,29,30].
Hence, in the following, we present two practical examples on a tree network.

5.2.1. Example 1

This problem represents a small city, and in this town there is a medical center facility that provides the town with several medical services.
The director of the medical center intends to implement a children’s vaccination campaign against polio, and then he formed two teams to achieve this aim. The resident blocks of the city are associated with the medical center by three roads: the first one is on the right of the medical center, the second is on the left of the medical center and the third is in front of the medical center.
However, both teams have to move in the two paths only and they cannot visit all resident blocks on the two roads. The financial capabilities to visit all facilities are not available.
So, we present a solution to this problem as follows.
We design the map of the city according description above as a tree network, we consider the medical center as a root of a tree and the three roads are edges associated with the root. See Figure 6.
We use Algorithm 7 to find the optimal path that will provide effort and money for the medical team.
Assume r is a root of the tree T 1 in Figure 6. From this figure, we show how Algorithm 7 runs.
The optimal path that we advise the team to go by is the red path, which is shown in Figure 6 and in Table 10.

5.2.2. Example 2

The objective is to locate a path of the length in Figure 7.
We are asked to select the best path on the tree network that will represent one path for a tram on a city.
Our Algorithm 7 finds this path, which is denoted by the P * and listed in Column 4 of Table 11, also denoted by the colored line on Figure 7.
Note 1: the minimum sum of the distance equals α = 234 .
Note 2: the maximum possible number obtained from this path compare to the other paths equals to δ = 134 .

6. Concluding Remarks

We have modified and improved several algorithms to obtain a developed and an efficient algorithm that finds an core of an unweighted tree network. The suggested algorithm is applied on a tree network that represents facilities in a large city. The aim of that is to specify the best path for public transportation to provide a service for a maximum number possible of people who are located at the facilities and neighborhoods of these facilities.
As a future investigation, one may consider a two-core problem of a weighted tree network.
A meta-heuristic strategy can be considered to develop algorithms solved with a problem tree network, for instance median path problems, central problems, and eccentricity problems. Hybridized algorithms for finding one-core or two-core of an unweighted and weighted tree will be considered.

Author Contributions

Conceptualization, A.A., M.E.-A. and M.A.; methodology, A.A., S.M. and M.A.; software, M.A. and S.M.; validation, A.A. and M.E.-A.; formal analysis, S.M. and A.A.; investigation, A.A. and S.M.; funding acquisition, M.A.; data curation, A.A., S.M. and M.A.; writing—original draft preparation, A.A., S.M. and M.A.; writing—review and editing, M.E.-A. and S.M.; visualization, S.M. and M.A.; supervision, A.A. and M.E.-A. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Data Availability Statement

Not applicable.

Conflicts of Interest

The authors declare that they have no conflicts of interest.

References

  1. Adalı, T.; Ortega, A. Applications of Graph Theory [Scanning the Issue]. Proc. IEEE 2018, 106, 784–786. [Google Scholar] [CrossRef]
  2. Žerovnik, J.; Poklukar, D.R. (Eds.) Advances in Discrete Applied Mathematics and Graph Theory; Multidisciplinary Digital Publishing Institute (MDPI): Basel, Switzerland, 2022. [Google Scholar]
  3. Beineke, L.W.; Wilson, R.J.; Cameron, P.J. Topics in Algebraic Graph Theory; Cambridge University Press: Cambridge, UK, 2004; Volume 102. [Google Scholar]
  4. Godsil, C.; Royle, G.F. Algebraic Graph Theory; Springer Science & Business Media: Berlin/Heidelberg, Germany, 2001; Volume 207. [Google Scholar]
  5. Deo, N. Graph Theory with Applications to Engineering and Computer Science; Courier Dover Publications: Mineola, NY, USA, 2017. [Google Scholar]
  6. Van Steen, M. An Introduction to Graph Theory and Complex Networks; Computer Science Department, VU Amsterdam: Amsterdam, The Netherlands, 2010. [Google Scholar]
  7. Avella, P.; Boccia, M.; Sforza, A.; Vasil’Ev, I. A branch-and-cut algorithm for the median-path problem. Comput. Optim. Appl. 2005, 32, 215–230. [Google Scholar] [CrossRef]
  8. Chamola, V.; Kotesh, P.; Agarwal, A.; Gupta, N.; Guizani, M. A comprehensive review of unmanned aerial vehicle attacks and neutralization techniques. Hoc Netw. 2021, 111, 102324. [Google Scholar] [CrossRef] [PubMed]
  9. Cui, S.; Chen, Y.; Li, X. A Robust and Efficient UAV Path Planning Approach for Tracking Agile Targets in Complex Environments. Machines 2022, 10, 931. [Google Scholar] [CrossRef]
  10. Fadhil, A.F.; Kanneganti, R.; Gupta, L.; Eberle, H.; Vaidyanathan, R. Fusion of enhanced and synthetic vision system images for runway and horizon detection. Sensors 2019, 19, 3802. [Google Scholar] [CrossRef] [PubMed]
  11. Hrabia, C.E.; Hessler, A.; Xu, Y.; Seibert, J.; Brehmer, J.; Albayrak, S. Efffeu project: Towards mission-guided application of drones in safety and security environments. Sensors 2019, 19, 973. [Google Scholar] [CrossRef] [PubMed]
  12. Kariv, O.; Hakimi, S.L. An algorithmic approach to network location problems. I: The p-centers. Siam J. Appl. Math. 1979, 37, 513–538. [Google Scholar] [CrossRef]
  13. Richey, M.B. Optimal location of a path or tree on a network with cycles. Networks 1990, 20, 391–407. [Google Scholar] [CrossRef]
  14. Becker, R.I. Inductive algorithms on finite trees. Quaest. Math. 1990, 13, 165–181. [Google Scholar] [CrossRef]
  15. Motevalli, S.; Fathali, J.; Zaferanieh, M. An efficient algorithm for finding the semi-obnoxious (k,l)-core of a tree. J. Math. Model. 2016, 3, 129–144. [Google Scholar]
  16. Ashkezari, S.; Fathali, J. On the finding 2-(k, l)-core of a tree with arbitrary real weight. Iran. J. Numer. Anal. Optim. 2019, 9, 93–104. [Google Scholar]
  17. Tamir, A. An O (pn2) algorithm for the p-median and related problems on tree graphs. Oper. Res. Lett. 1996, 19, 59–64. [Google Scholar] [CrossRef]
  18. Dankelmann, P.; Osaye, F.J. Average eccentricity, k-packing and k-domination in graphs. Discret. Math. 2019, 342, 1261–1274. [Google Scholar] [CrossRef]
  19. Wang, B.F.; Peng, S.; Yu, H.Y.; Ku, S.C. Efficient algorithms for a constrained k-tree core problem in a tree network. J. Algorithms 2006, 59, 107–124. [Google Scholar] [CrossRef]
  20. Moshtagh, M.; Fathali, J.; Smith, J.M.; Mahdavi-Amiri, N. Finding an optimal core on a tree network with M/G/c/c state-dependent queues. Math. Methods Oper. Res. 2019, 89, 115–142. [Google Scholar] [CrossRef]
  21. Becker, R.I.; Chang, Y.I.; Lari, I.; Scozzari, A.; Storchi, G. Finding the l-core of a tree. Discret. Appl. Math. 2002, 118, 25–42. [Google Scholar] [CrossRef]
  22. Dvir, A.; Segal, M. The (k, l) coredian tree for ad hoc Networks. In Proceedings of the 2008 The 28th International Conference on Distributed Computing Systems Workshops, Beijing, China, 17–20 June 2008; pp. 267–272. [Google Scholar]
  23. Kim, T.U.; Lowe, T.J.; Tamir, A.; Ward, J.E. On the location of a tree-shaped facility. Netw. Int. J. 1996, 28, 167–175. [Google Scholar] [CrossRef]
  24. Morgan, C.A.; Slater, P.J. A linear algorithm for a core of a tree. J. Algorithms 1980, 1, 247–258. [Google Scholar] [CrossRef]
  25. Peng, S.; Lo, W.t. Efficient algorithms for finding a core of a tree with a specified length. J. Algorithms 1996, 20, 445–458. [Google Scholar] [CrossRef]
  26. Cormen, T.H.; Leiserson, C.E.; Rivest, R.L.; Stein, C. Introduction to Algorithms; MIT Press: Cambridge, MA, USA, 2009. [Google Scholar]
  27. Alstrup, S.; Lauridsen, P.W.; Sommerlund, P.; Thorup, M. Finding cores of limited length. In Proceedings of the Workshop on Algorithms and Data Structures, Halifax, NS, Canada, 6–8 August 1997; Springer: Berlin/Heidelberg, Germany, 1997; pp. 45–54. [Google Scholar]
  28. Ma, B.; Wu, B.; Zhang, W. Proximity and average eccentricity of a graph. Inf. Process. Lett. 2012, 112, 392–395. [Google Scholar] [CrossRef]
  29. Batta, R.; Berman, O. A location model for a facility operating as an M/G/k queue. Networks 1989, 19, 717–728. [Google Scholar] [CrossRef]
  30. Brandeau, M.L.; Chiu, S.S. A center location problem with congestion. Ann. Oper. Res. 1992, 40, 17–32. [Google Scholar] [CrossRef]
Figure 1. Tree network T s .
Figure 1. Tree network T s .
Mathematics 11 03585 g001
Figure 2. By deleting the edge ( d , v ) of the T s , two subtrees are obtained upper subtree Fa d and lower subtree Sn v .
Figure 2. By deleting the edge ( d , v ) of the T s , two subtrees are obtained upper subtree Fa d and lower subtree Sn v .
Mathematics 11 03585 g002
Figure 3. Two subtrees result from deleting the edge fs = ( d , v ) of the original tree T s .
Figure 3. Two subtrees result from deleting the edge fs = ( d , v ) of the original tree T s .
Mathematics 11 03585 g003
Figure 4. Example of showing the computing of the “msdsn” and “msdfa”.
Figure 4. Example of showing the computing of the “msdsn” and “msdfa”.
Mathematics 11 03585 g004
Figure 5. Flowchart of the developed and efficient median path algorithm.
Figure 5. Flowchart of the developed and efficient median path algorithm.
Mathematics 11 03585 g005
Figure 6. Directed tree network a medical center facility in town.
Figure 6. Directed tree network a medical center facility in town.
Mathematics 11 03585 g006
Figure 7. Directed tree network with 80 vertices and 79 edges.
Figure 7. Directed tree network with 80 vertices and 79 edges.
Mathematics 11 03585 g007
Table 1. The values of “msdsn” for paths of different lengths to b, (D, W), (W, H) in Figure 4.
Table 1. The values of “msdsn” for paths of different lengths to b, (D, W), (W, H) in Figure 4.
fs | Sn sn | msdsn(fs,1)msdsn2 c 1 msdfa(fs,2)msdsn2msdsn(fs,3)msdsn2
(b,A)611(A,a)
(b,Q)1111(Q,q)
(b,D)2118 (D,W)35 4039
(D,W)1817 (W,H)22212322
(W,H)1754(H, h 3 )65
Table 2. The values of “msdfa” for paths of different lengths to b, (D, W), (W, H) in Figure 4.
Table 2. The values of “msdfa” for paths of different lengths to b, (D, W), (W, H) in Figure 4.
fsmsdfa(fs,1)msdfa(fs,2)msdfa(fs,3)msdfa(fs,4)msdfa(fs,5)msdfa(fs,6)
(b,A)2139566162
(b,Q)2139566162
(b,D)1112
(D,W)182930
(W,H)21395051
Table 3. The distancesum of d ( sn ) for paths of different lengths to b, (D, W), (W, H) in Figure 4.
Table 3. The distancesum of d ( sn ) for paths of different lengths to b, (D, W), (W, H) in Figure 4.
fsd(sn)0d(sn)1d(sn)2d(sn)3d(sn)4d(sn)5
(b,A)54
(b,Q)109
(b,D)6547302524
(D,W)45282322
(W,H)282322
Table 4. The distancesum of d ( fa ) for paths of different lengths to b, (D, W), (W, H) in Figure 4.
Table 4. The distancesum of d ( fa ) for paths of different lengths to b, (D, W), (W, H) in Figure 4.
fsd(fa)0d(fa)1d(fa)2d(fa)3d(fa)4d(fa)5d(fa)6
(b,A)1078668514645
(b,Q)977658413635
(b,D)322120
(D,W)52342322
(W,H)7352342322
Table 5. Keeping the d ( sn ) at minimum at locations connected to b and (W;H) in Figure 4.
Table 5. Keeping the d ( sn ) at minimum at locations connected to b and (W;H) in Figure 4.
fskd(sn)0kd(sn)1kd(sn)2kd(sn)3kd(sn)4kd(sn)5
(b,A)544444
(b,Q)1099999
(b,D)654730252424
(D,W)452823222222
(W,H)282322222222
Table 6. Keeping the d ( fa ) at minimum at locations connected to b and (W;H) in Figure 4.
Table 6. Keeping the d ( fa ) at minimum at locations connected to b and (W;H) in Figure 4.
fskd(fa)0kd(fa)1kd(fa)2kd(fa)3kd(fa)4kd(fa)5kd(fa)6
(b,A)107866851464545
(b,Q)97765841363535
(b,D)32212020202020
(D,W)52342322222222
(W,H)73523423222222
Table 7. Picking the best edge in the subtree (lower) Sn sn in Figure 4.
Table 7. Picking the best edge in the subtree (lower) Sn sn in Figure 4.
ψ (fs,1) ψ (fs,2) ψ (fs,3) ψ (fs,4) ψ (fs,5)
(b,A)112111111111111
(b,Q)107106106106106
(b,D) 97 79 ( D , W ) 62 ( W , H ) 5756
(D,W)9780757474
(W,H)10196959595
Table 8. Picking the best edge in the subtree (upper) Fa fa in Figure 4.
Table 8. Picking the best edge in the subtree (upper) Fa fa in Figure 4.
μ (fs,1) μ (fs,2) μ (fs,3) μ (fs,4) μ (fs,5)
(b,A)11291735651
(b,Q)1078668 51 ( b , Q ) 46 ( Q , q )
(b,D) 97 86858585
(D,W)9779686767
(W,H)10180 62 51 50
Table 9. The one-core path with length = 5 for the tree T r in Figure 4.
Table 9. The one-core path with length = 5 for the tree T r in Figure 4.
α δ P *
97211 p 1 = ( b , D )
79392 p 2 = p 1 ( D , W )
62563 p 3 = p 2 ( W , H )
51674 p 4 = p 3 ( b , Q )
46725 p 5 = p 4 ( H , h 3 )
Table 10. The one-core path with length = 6 for the tree T 1 in Figure 6.
Table 10. The one-core path with length = 6 for the tree T 1 in Figure 6.
α δ P *
178401 p 1 = ( r , d ) .
147712 p 2 = p 1 , ( d , m ) .
124943 p 3 = p 2 , ( r , h ) .
1111074 p 4 = p 3 , ( h , g ) .
1101085 p 5 = p 4 , ( g , g i ) or p 4 , ( m , m i ) .
1091096 p 6 = p 4 , ( g , g i ) , ( m , m i ) .
Table 11. The one-core path with length = 16 for the tree in Figure 7.
Table 11. The one-core path with length = 16 for the tree in Figure 7.
α δ P *
348201 p 1 = ( 1 , 21 )
328402 p 2 = ( 1 , 21 ) , ( 1 , 41 ) .
309593 p 3 = ( 1 , 21 ) , ( 1 , 41 ) , ( 21 , 22 ) .
293754 p 4 = ( 1 , 21 ) , ( 1 , 41 ) , ( 21 , 22 ) , ( 41 , 42 ) .
280885 p 5 = p 4 , ( 2 , 23 ) .
270986 p 6 = p 5 , ( 42 , 48 ) .
2611077 p 7 = p 6 , ( 48 , 49 ) .
2541148 p 8 = p 7 , ( 23 , 24 ) .
2501189 p 9 = p 8 , ( 24 , 27 ) or p 8 , ( 49 , 50 ) ( 49 , 54 ) .
24612210 p 10 = p 8 , ( 24 , 27 ) , ( 49 , 50 ) ( 49 , 54 ) .
24312511 p 11 = p 10 , ( 27 , 28 ) or p 10 , ( 50 , 51 ) ( 54 , 55 ) .
24012812 p 12 = p 10 , ( 27 , 28 ) , ( 50 , 51 ) ( 54 , 55 ) .
23813013 p 13 = p 12 , ( 28 , 29 ) or p 12 , ( 51 , 52 ) ( 55 , 56 ) .
23613214 p 14 = p 12 , ( 28 , 29 ) , ( 51 , 52 ) ( 55 , 56 ) .
23513315 p 15 = p 14 , ( 29 , 30 ) or p 14 , ( 52 , 53 ) ( 56 , 57 ) .
23413416 p 16 = p 14 , ( 29 , 30 ) , ( 52 , 53 ) ( 56 , 57 ) .
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Aboutahoun, A.; Mahdi, S.; El-Alem, M.; ALrashidi, M. Modified and Improved Algorithm for Finding a Median Path with a Specific Length () for a Tree Network. Mathematics 2023, 11, 3585. https://doi.org/10.3390/math11163585

AMA Style

Aboutahoun A, Mahdi S, El-Alem M, ALrashidi M. Modified and Improved Algorithm for Finding a Median Path with a Specific Length () for a Tree Network. Mathematics. 2023; 11(16):3585. https://doi.org/10.3390/math11163585

Chicago/Turabian Style

Aboutahoun, Abdallah, Salem Mahdi, Mahmoud El-Alem, and Mohamed ALrashidi. 2023. "Modified and Improved Algorithm for Finding a Median Path with a Specific Length () for a Tree Network" Mathematics 11, no. 16: 3585. https://doi.org/10.3390/math11163585

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop