1 Introduction

Let G be an undirected simple graph. Let \(V_G\) and \(E_G\) be its vertex set and edge set, respectively. Then \({n}(G)=|V_G|\) and \(\varepsilon (G)=|E_G|\) are its order and size, respectively. Let uv be in \(V_G\) and \(e = xy\) be in \(E_G\). The distance between u and v is denoted by d(uv). Let \(n_x(e)=\{w\in V_G|{d(}w,x)<{d(}w,y)\}\) and \(n_y(e)=\{w\in V_G|{d(}w,y)<{d(}w,x)\}\). Then \(\phi (e)=|n_x(e)-n_y(e)|\) is the contribution of e. The sum \(Mo(G)=\sum _{e\in E_G}\phi (e)\) is called the Mostar index of G.

The Mostar index was proposed by Došlić et al. [12], which was defined to measure how far a graph is from distance-balanced, where a distance-balanced graph [6, 11, 18, 20, 21] is one of Mostar index zero. In [12], the extremal unicyclic graphs and trees respect to the Mostar index were obtained, respectively. After that, with respect to the extremal value of the index, the bicyclic graphs [24], cacti [14], trees with given parameters [9, 15], hexagonal chains [17, 25, 26], tree-like benzenoid compounds [7, 10], chemical trees [8] and so on were studied. The edge version of the index was also studied [1, 5, 19, 23] recently. The most recent article [2] stated more modifications and generalizations of the Mostar index.

Let T be a tree, v be in \(V_T\) and d(v) be the degree of v. Then v is a d-vertex if \({d(}v)=d\) and is a \(d^+\)-vertex if \({d(}v)\ge d\). Each 1-vertex in T is called a leaf; each \(3^+\)-vertex is called a branch vertex. A segment in T is a path, where the inner vertices are all 2-vertices, and none of the ends is a 2-vertex. A segment is pendent if it has a pendent edge and is non-pendent otherwise. The length sequence of all segments in T in order from largest to smallest is called its segment sequence.

The tree set \({\mathcal {T}}^{L}\) with a fixed segment sequence L, and the tree set \({\mathcal {T}}(\varepsilon ,k)\) with a fixed size \(\varepsilon \) and together with a fixed segment number k, have attracted more and more researchers’ attentions, with respect to many extremal problems [3, 4, 22, 27, 28]. For a graph set \({\mathcal {X}}\), let \({\mathcal {X}}^{\max }\) and \({\mathcal {X}}^{\min }\) be its subsets with the greatest and the least Mostar indices, respectively. Let \(Mo({\mathcal {X}}^{\max })\) and \(Mo({\mathcal {X}}^{\min })\) be the Mostar indices of graphs in the corresponding sets. This paper completely determines \({\mathcal {T}}^{L \max }\), \({\mathcal {T}}^ {\max }(\varepsilon ,k)\) and \({\mathcal {T}}^ {\min }(\varepsilon ,k)\), and their Mostar indices.

First, we find \({\mathcal {T}}^{L \max }\) and their Mostar index. Let \(L=(l_1,l_2,\ldots ,l_k)\) where \(k\ge 3\), each \(l_i\) (\(i=1,2,{\ldots },k\)) is a positive integer, and \(l_i\ge l_j\) whenever \(i< j\). Then, the sum \(\varepsilon (L)=\sum _{i=1}^kl_i\) is called the size of L. The unique tree \(T^{L}_S\), in \({\mathcal {T}}^{L}\), which has exactly one branch vertex is called a starlike tree, as shown in Fig. 1a.

Theorem 1.1

Let T be in \({\mathcal {T}}^{L}\), where \(L=(l_1,l_2,{\ldots },l_k)\), \(k\ge 3\) and \(l_i\ge l_j\) whenever \(i<j\). Let \(\varepsilon =\varepsilon (L)\). Then

$$\begin{aligned} Mo(T)\le \left\{ \begin{array}{lllllll} \varepsilon (\varepsilon +1)-2\sum _{i=1}^{k}\sum _{j=1}^{l_i}j, &{} \quad \mathrm{if } \,\, l_1\le (\varepsilon +1)/2; \\ \sum _{j=1}^{l_1}|\varepsilon +1-2j|+ (\varepsilon +1)(\varepsilon -1) -2\sum _{i=2}^{k}\sum _{j=1}^{l_i}j, &{} \quad \mathrm{if }\,\, l_1\ge (\varepsilon +1)/2+1, \end{array} \right. \end{aligned}$$

where the equality holds if and only if \(T\cong T^{L}_S\).

Fig. 1
figure 1

a \(T^L_S\) where \(L=(4,3,3,2,2,1,1)\); b \(T_S(12,5)\)

Second, we obtain \({\mathcal {T}}^{\max } (\varepsilon ,k)\) and their Mostar index, based on Theorem 1.1. Let \(3\le k\le \varepsilon \). Suppose \(\varepsilon =\alpha k+\beta \), where \(0\le \beta \le k-1\). Let \(L_S(\varepsilon ,k)= (\alpha ,{\ldots },\alpha ,\alpha +1,{\ldots },\alpha +1)\) be a segment sequence of size \(\varepsilon \) with k integers. Let \(T_S(\varepsilon ,k)=T^{L_S(\varepsilon ,k)}_S\) for short. Figure 1b shows the graph \(T_S(12,5)\).

Theorem 1.2

Let \(T\in {\mathcal {T}} (\varepsilon ,k)\) \({(}3\le k\le \varepsilon {)}\), where \(\varepsilon =\alpha k+\beta \), with \(\alpha \), \(\beta \) being nonnegative integers, and \(0\le \beta \le k-1\). Then

$$\begin{aligned} Mo(T)\le (\varepsilon +1)^2-(\beta +\varepsilon +1)(\alpha +1) \end{aligned}$$

where the equality holds if and only if \(T\cong T_S(\varepsilon ,k)\).

Third, we obtain \({\mathcal {T}}^{\min } (\varepsilon ,k)\) and their Mostar index. A tree is called a caterpillar if its \(2^+\)-vertices induce a path. Let \(L_C(\varepsilon ,k)=(\varepsilon -k+1 ,1,1,{\ldots },1)\) be a sequence of size \(\varepsilon \) with k integers. A tree in \({\mathcal {T}}^{L_C(\varepsilon ,k)}\) is called a balanced caterpillar (denoted by \(T_C(\varepsilon ,k)\)) if the followings hold: (1) \(T_C(\varepsilon ,k)\) is a caterpillar; (2) there is exactly one \(4^+\)-vertex when \(k=2t\) for some integer t, and there is no \(4^+\)-vertex otherwise; (3) the numbers \(\varepsilon _1\) and \(\varepsilon _2\) of edges in the resulted two non-empty components after deleting the longest segment satisfy that \(|\varepsilon _1-\varepsilon _2|\le 2\). Figure 2a–d shows \(T_C(8,6),T_C(9,7),T_C(10,8)\) and \(T_C(11,9)\), respectively.

Fig. 2
figure 2

a \(T_C(8,6)\); b \(T_C(9,7)\); c \(T_C(10,8)\); d \(T_C(11,9)\)

Theorem 1.3

Let T be a tree in \({\mathcal {T}} (\varepsilon ,k)\), where \(3\le k\le \varepsilon \). Then

$$\begin{aligned} Mo(T)\ge \left\{ \begin{array}{lllllll} \lfloor \frac{\varepsilon ^2}{2}\rfloor +2, &{} \quad \mathrm{if}\quad k=3; \\ 12, &{} \quad \mathrm{if}\quad k=4 \,\mathrm{and}\, \varepsilon = 4; \\ \lfloor \frac{\varepsilon ^2}{2}\rfloor +6, &{} \quad \mathrm{if}\quad k=4 \,\mathrm{and}\, \varepsilon \ge 5 ; \\ \lceil \frac{(\varepsilon +1)^2}{2}\rceil -(\varepsilon +1)+\frac{(k-1)^2}{4}, &{} \quad \mathrm{if}\quad k=4t+1\ (t\ge 1); \\ \lceil \frac{(\varepsilon +1)^2}{2}\rceil -\varepsilon +\frac{(k-1)^2}{4}, &{} \quad \mathrm{if}\quad k=4t+3\ (t\ge 1); \\ \lceil \frac{(\varepsilon +1)^2}{2}\rceil -\varepsilon +\frac{(k-1)^2+5}{4}, &{} \quad \mathrm{if}\quad k=2t\ (t\ge 3) \end{array} \right. \end{aligned}$$

where the equality holds if and only if \(T\cong T_C(\varepsilon ,k)\).

In Sect. 2, we introduce the moving operations and their properties. By using these properties, Theorems 1.1, 1.2 are proved in Sect. 3, and Theorem 1.3 is shown in Sect. 4. The last section gives some conclusion remarks.

2 Preliminaries and Moving Operations

Let T be a tree of size \(\varepsilon \) and order \({n}=\varepsilon +1\). T is central at \(v^*\) if there is a vertex \(v^*\), such that \((T-v^*)\) consists of components of order less than n/2. Then \(v^*\) is called the center. T is edge central at \(e^*\), if there is an edge \(e^*=v_1^*v_2^*\), such that \((T-e^*)\) consists of two components of order exactly n/2. Then \(e^*\) is called the edge center. Figure 3 shows examples of the (edge) central tree. One has that every tree is either central or edge central, as stated early in [13].

Fig. 3
figure 3

a A tree central at \(v^*\); b a tree edge central at \(e^*\)

Let \(u,w\in V_T\), \(e=uu_1\), \(f=ww_1\in E_T\), and \(F\subseteq E_T\). N(v) and E(v) are the neighbor set and incident edge set of v, respectively. Let \(P_{u,w}\) be the path with ends u, w. Suppose \({d(}w,u)<{d(}w,u_1)\) and \({d(}u,w)<{d(}u,w_1)\); then, we define \(P_{x,y}=P_{w,u}\) to be the path between x and y for \((x,y)=(e,f),(w,e),(u,f)\), and let \({d(}x,y)=|E_{P_{x,y}}|\). For short, let P(x) be the path from x to the (edge) center if x is a vertex or an edge, and let \({d(}x)=|E_{P(x)}|\).

Each element in \(V_{P(v)}\) and \(E_{P(v)}\) is called an ancestor and an ancestor edge of v, respectively. If v is in P(u), then each element in \(V_{P_{v,u}}\) and \(E_{P_{v,u}}\) is called a successor and a successor edge of v, respectively. Let S(v) and ES(v) be the successor set and successor edge set of v, respectively. Let \(S(e)=S(u_1)\) where we assume \({d(}u)<{d(}u_1)\). Let \(S(F)=\cup _{e'\in F}S(e')\). Let \({\sigma }(v)=|S(z)|\) for \(z=v\), e and F, respectively.

Suppose T is central at \(v^*\). Let \(v_i\in N(v^*)\). The graph \(T_{v_i}\) induced by \(S(v_i)\) is called a \(v_i\)-successor subtree, and the graph \(T_{v_iv^*}\) induced by \((S(v_i)\cup \{v^*\})\) is called a \(v_i\)-extended successor subtree.

Suppose T is edge central at \(e^*=v_1^*v_2^*\). For \(i=1,2\), the \(v_i^*\)-extended successor subtree \(T_{v_i^*}\) is the one induced by \(S(v_i^*)\).

Definition 1

Suppose \(F=\{e_i|e_i=uu_i, i=1,2,{\ldots },t\}\subseteq (E(u)\cap ES(u))\) and \(v\in (V_T\setminus S(F))\). The moving operation on (Fv) is the following transformation: first delete F, and second add the edges \(\{vu_i|i=1,2,{\ldots },t\}\). Let \(T(F^-, v^+)\) be the newly obtained graph.

Definition 2

Suppose \(e_1=w_1w_2, e_2=w_3w_4\) are two edges other than the edge center, such that \({d(}w_i)<{d(}w_{i+1})\) for \(i=1,3\). The moving operation on \((e_1,e_2)\) is the following transformation: first delete \(e_1,e_2\), and second add the edges \(w_3w_2\) and \(w_1w_4\) (let \(e_1=w_2w_1\) and \(e_2=w_1w_4\), too). Let \(T(e_1,e_2)\) be the newly obtained graph.

Fig. 4
figure 4

a Moving operation on (Fv); b moving operation on \((e_1,e_2)\)

Figure 4 shows examples for the graph transformations in Definitions 1 and 2.

Lemma 2.1

([9]) Let T be a tree with a being the center \(v^*\) or edge center \(e^*=v_1^*v_2^*\). Choose \(u, v\in V_T\), \(F\subseteq [E(u)\cap ES(u)]\) such that \(v\notin S(F)\). Let \(T_1=T(F^-,v^+)\).

  1. (1)

    If uv are in the same extended branch and u is not the center when T is central, then \(Mo(T_1)= Mo(T)+2\sigma (F)(d(u,a)-d(v,a))\).

  2. (2)

    Suppose T is \(v^*\)-central and uv are in distinct branches \(T_{v_1}\) and \(T_{v_2}\), respectively.

    • If \(\sigma (v_2)\leqslant \lceil n/2\rceil -\sigma (F)-1\), then \(Mo(T_1)= Mo(T)+2\sigma (F)(d(u,v^*)-d(v,v^*))\).

    • If n is even and \(\sigma (v_2)= n/2-\sigma (F)\) and \(d(u,v^*)=d(v,v^*)\), then \(T_1\) is \(v^*v_2\)-edge central and \(Mo(T_1)= Mo(T)\).

    • If n is odd and \(\sigma (v_2)= (n+1)/2-\sigma (F)\), then \(Mo(T_1)= Mo(T)+2\sigma (F)(d(u,v^*)-d(v,v^*)+1)\).

    • If \(\sigma (v_2)\ge \lceil n/2\rceil -\sigma (F)\) and \(d(u,v^*)>d(v,v^*)\), then \(Mo(T_1)> Mo(T)\).

  3. (3)

    Suppose T is \(v_1^*v_2^*\)-edge central, \(u\in V_{T_{v_1^*}}\), \(v\in V_{T_{v_2^*}}\)

    • If \(d(u,v_1^*)\ge d(v,v_2^*)\), then \(Mo(T_1)> Mo(T)\).

    • If \(d(u,v_1^*)= d(v,v_2^*)-1\) and \(T_1\) is \(v_2^*\)-central, then \(Mo(T_1)= Mo(T)\).

Lemma 2.2

  1. (1)

    Suppose T is a tree of order n which is central at \(v^*\). Let \(v_1\) and \(v_2\) be two vertices adjacent to \(v^*\). Suppose u and v are in \(T_{v^*v_1}\) and \(T_{v_2}\), respectively. Let F be a subset of \([(E(u)\cap ES(u))\setminus \{v^*v_2\}]\).

    • If \(|T_{v_2}|> \lceil n/2\rceil -{\sigma }(F)\) and \({d(}u)\ge {d(}v)\), then \(Mo(T(F^-,v^+))>Mo(T)\).

    • If \(|T_{v_2}|= {n}/2-{\sigma }(F)\) and \({d(}u)\le {d(}v)-1\), then \(T(F^-,v^+)\) is edge central at \(v^*v_2\) and \(Mo(T(F^-,v^+))< Mo(T)\).

  2. (2)

    Suppose T is central at \(v^*\), which admits at least three neighbors \(v_1,v_2,v_3\). Let \(e_i=v^*\) for \(i=1,2,3\). Let \(e_4=w_1w_2\) be an edge in \(T_{v_1}\) with \({d(}w_1)<{d(}w_2)\).

    • Suppose \(|T_{v_2}|\ge |T_{v_1}|\) and \(F\subseteq (E(v^*)\setminus \{e_1,e_2\})\). Then \(Mo(T(F^-,w_1^+))< Mo(T)\).

    • Suppose \(|T_{v_1}|\le |T_{v_2}|\) and \(|T_{v_1}|\le |T_{v_3}|\). Then \(Mo(T(e_2,e_4))<Mo(T)\) and \(Mo(T(e_3,e_4))<Mo(T)\).

  3. (3)

    Suppose u and v belong to two different extended successor subtrees of T, or u is the center. Let F be a subset of \([E(u)\cap ES(u)]\) such that F contains no edge of the extended successor subtree that contains v.

    • If \({d(}v)\ge {d(}u)+{\sigma }(F)\), then \(Mo(T(F^-,v^+))\le Mo(T)\).

    • If \({d(}v)\ge {d(}u)+{\sigma }(F)+1\), then \(Mo(T(F^-,v^+))< Mo(T)\).

Proof

Let \(\phi (e)\) be the contribution of e in T.

  1. (1)

    Let \({\phi _1}(e)\) be the contribution of e in \(T(F^-,v^+)\). Then \({\phi _1}(e)=\phi (e)\) for each \(e\in (E_T\setminus E_{P_{u,v}})\). If \(|T_{v_2}|> \lceil {n}/2\rceil -{\sigma }(F)\) and \({d(}u)\ge {d(}v)\), then the (edge) center of \(T(F^-,v^+)\) is in \({P_{v_2,v}}\). One has \({\phi _1}(e)={\phi }(e)+2{\sigma }(F)\) for \(e\in E_{P_{v^*,u}}\); \({\phi _1}(e)=|{\phi }(e)-2{\sigma }(F)|\ge {\phi }(e)-2{\sigma }(F)\) for \(e\in E_{P_{v_2,v}}\). What is more, \({\phi _1}(v^*v_2)=|{\phi }(v^*v_2)-2{\sigma }(F)|=|n-2{\sigma }(v_2)-2{\sigma }(F)| >{n}-2{\sigma }(v_2)-2{\sigma }(F)={\phi }(v^*v_2)-2{\sigma }(F)\) since \(|T_{v_2}| >\lceil {n}/2\rceil -{\sigma }(F)\). Thus, \(Mo(T(F^-,v^+))>Mo(T)\) since \({d(}u)\ge {d(}v)>{d(}v_2,v)\). If \(|T_{v_2}|= {n}/2-{\sigma }(F)\) and \({d(}u)\le {d(}v)-1\), then \(T(F^-,v^+)\) is edge central at \(v^*v_2\). So \(0={\phi _1}(v^*v_2)<{\phi }(v^*v_2)\) and \({\phi _1}(e)={\phi }(e)+2{\sigma }(F)\) for \(e\in E_{P_{v^*,u}}\). Note that \({\phi _1}(e)= {\phi }(e)-2{\sigma }(F)\) for \(e\in E_{P_{v_2,v}}\). Thus, \(Mo(T(F^-,v^+))<Mo(T)\) since \({d(}u)\le {d(}v)-1= {d(}v_2,v)\).

  2. (2)

    One has that the (edge) center of \(T(F^-,w_1^+)\), \(T(e_2,e_4)\) and \(T(e_3,e_4)\) is in \(P_{w_1,v^*}\). Let \({\phi _1}(e)\) be the contribution of e in \(T(F^-,w_1^+)\). Let \({\phi _2}(e)\) be the contribution of e in \(T(e_2,e_4)\). Then \({\phi _i}(e)=\phi (e)\) (\(i=1,2\)) for \(e\in (E_T\setminus E_{P_{w_1,v^*}})\). For the first item, if \(|T_{v_1}|\le |T_{v_2}|\), then \({\sigma }_{T}(e_2)\ge {\sigma }_{T}(e_1)>{\sigma }_{T}(e_4)>0\). Then for each \(e\in E_{P_{w_1,v^*}}\), one has \({\phi _1}(e)={\phi }(e)-2{\sigma }_{T}(F)\) or \({\phi _1}(e)\le {n}-2{\sigma }_{T}(e_2)-2\le {n}-2{\sigma }_{T}(e_1)-2\le {\phi }(e)-2\). So \(Mo(T(F^-,w_1^+))< Mo(T)\). Thus, the first item holds. For the second item, it is sufficient to show the conclusion for \(T(e_2,e_4)\). For each \(e\in E_{P_{w_1,v^*}}\), one has \({\sigma }_{T(e_2,e_4)}(e)={\sigma }_{T}(e) +({\sigma }_{T}(e_2)-{\sigma }_{T}(e_4)) >{\sigma }_{T}(e)\) or \({{\sigma }_{T(e_2,e_4)}(e)\ge {\sigma }_{T}(e_3)+{\sigma }_{T}(e_4)} >{\sigma }_{T}(e)\). That is \({\phi _2}(e)={n}-2{\sigma }_{T(e_2,e_4)}(e) <{n}-2{\sigma }_{T}(e)={\phi }(e)\). So \(Mo(T(e_2,e_4))<Mo(T)\). Thus, the second item also holds.

  3. (3)

    Let \(T_1=T(F^-,v^+)\) and \({\phi _1}(e)\) be the contribution of e in \(T_1\).

Case 1 If \({d(}v)\ge {d(}u)+{\sigma }(F)\).

Let P be the path between v and the (edge) center of T. Note that the (edge) center \(a_1\) of \(T_1\) is in P. One has \({\phi _1}(e)=\phi (e)\) for \(e\in (E_T\setminus E_{P_{u,v}})\); \(\phi _1(e)=\phi (e)+2{\sigma }(F)\) for e in \(P_{u,a}\). Similarly, \(\phi _1(e)=\phi (e)-2{\sigma }(F)\) for e in \(P_{a_1,v}\).

Suppose T is central at \(v^*\), \(u\in V_{T_{v^*v_1}}\) and \(v\in V_{T_{v_2}}\) where \(v_1,v_2 \in N(v^*)\). If \(T_1\) is central at \(w^*\), let \(w^*w_1\) be the edge in \(P_{v^*,w^*}\). Let \({\sigma }_t= |S_T(v_2)\setminus (S_T(w^*)\cup V_{P_{v_2,w_1}})|\). Then \({\sigma }_t+|P_{v_2,w_1}|<{\sigma }(F)\), since \({\sigma }_{T_1}(w_1)\le ({n}-1)/2\) (because \(T_1\) is central at \(w^*\)) and \((|T|-{\sigma }_T(v_2))\ge ({n}+1)/2\) (because T is central at \(v^*\)). Note that

$$\begin{aligned} \begin{array}{lllllll} \phi _1(w^*w_1)&{}=&{}{n}-2{\sigma }_{T_1}(w_1)\\ &{}=&{}{n}-2[{n}-{\sigma }_T(v_2)-{\sigma }_T(F) +({\sigma }_t+|P_{v_2,w_1}|)]\\ &{}=&{}2[{\sigma }_T(v_2)+{\sigma }_T(F) -({\sigma }_t+|P_{v_2,w_1}|)]-{n}\\ &{}=&{}2[{\sigma }_T(F) -({\sigma }_t+|P_{v_2,w_1}|)]-({n}-2{\sigma }_T(v_2))\\ &{}=&{}2[{\sigma }_T(F) -({\sigma }_t+|P_{v_2,w_1}|)]-\phi (v^*v_2).\end{array} \end{aligned}$$

Then, for \(e\in E_{P_{v^*,w^*}}\), one has

$$\begin{aligned} \begin{array}{lllllll} \phi _1(e)&{}\le &{}\phi (w^*w_1)+2({\sigma }_t+{d(}e,w^*))\\ &{}=&{}2[{\sigma }_T(F) -({\sigma }_t+|P_{v_2,w_1}|)]-\phi (v^*v_2) +2({\sigma }_t+{d(}e,w^*))\\ &{}=&{}2({\sigma }_T(F) -|P_{v_2,w_1}|)-\phi (v^*v_2) +2{d(}e,w^*),\end{array} \end{aligned}$$

whereas for \({\bar{e}}\in E_{P_{v^*,w^*}}\), one has

$$\begin{aligned} \phi ({\bar{e}})\ge \phi (v^*v_2)+2{d(}{\bar{e}},v^*). \end{aligned}$$

So for \(e,{\bar{e}}\in E_{P_{v^*,w^*}}\) satisfying \({d(}v^*,e)={d(}w^*,{\bar{e}})\), one has

$$\begin{aligned} \begin{array}{lllllll} \phi _1(e)-\phi (\bar{{e}})&{}\le &{}2({\sigma }_T(F) -|P_{v_2,w_1}|)-2\phi (v^*v_2)\\ &{}\le &{}2({\sigma }_T(F) -|P_{v_2,w_1}|-1)\\ &{}=&{}2({\sigma }_T(F) -{d(}v^*,w^*)).\end{array} \end{aligned}$$

This gives

$$\begin{aligned} \begin{array}{lllllll} Mo(T_1) &{}\le &{} Mo(T) +2{d(}u,v^*){\sigma }(F)\\ &{}&{}+2{d(}v^*,w^*)({\sigma }(F)-{d(}v^*,w^*)) -2{d(}w^*,v){\sigma }(F)\\ &{}=&{} Mo(T) +2{d(}u,v^*){\sigma }(F) +2{d(}v^*,w^*)({\sigma }(F)-{d(}v^*,w^*)) \\ &{}&{}-2({d(}v^*,v)-{d(}v^*,w^*)){\sigma }(F)\\ &{}\le &{} Mo(T) +2{d(}u,v^*){\sigma }(F) +2{d(}v^*,w^*)({\sigma }(F)-{d(}v^*,w^*)) \\ &{}&{}-2({d(}v^*,u)+2{\sigma }(F)-{d(}v^*,w^*)){\sigma }(F)\\ &{}=&{}Mo(T) -2({\sigma }(F))^2 +2{d(}v^*,w^*)(2{\sigma }(F)-{d(}v^*,w^*))\\ &{}=&{} Mo(T) -2({\sigma }(F)-{d(}v^*,w^*))^2. \end{array} \end{aligned}$$

So \(Mo(T_1)\le Mo(T)\).

If \(T_1\) is edge central at \(w_1^*w_2^*\) where \({d(}w^*_1,v^*)< {d(}w^*_2,v^*)\), let \({\sigma }_t= |S_T(v_2)\setminus (S_T(w_2^*)\cup V_{P_{v_2,w_1^*}})|\). Then \({\sigma }_t+|P_{v_2,w_1^*}|<{\sigma }(F)\), since \({\sigma }_{T_1}(w^*_1)= {n}/2\) (because \(T_1\) is edge central at \(w_1^*w_2^*\)) and \((|T|-{\sigma }(v_2))\ge ({n}+2)/2\). That is \({d(}v^*,w_2^*)\le {\sigma }(F)-{\sigma }_t\). Note that \(\phi _1(e)\le \phi ({\bar{e}})+2{\sigma }_t\) for \(e,{\bar{e}}\in E_{P_{v^*,w_2^*}}\) satisfying \({d(}v^*,e)={d(}w^*,{\bar{e}})\). So

$$\begin{aligned} Mo(T_1)\le & {} Mo(T_1)+2{d(}u,v^*){\sigma }(F)+2{d(}v^*,w_2^*){\sigma }_t -2{d(}w_2^*,v){\sigma }(F)\\\le & {} Mo(T_1)+2{d(}u,v^*){\sigma }(F)+2({\sigma }(F)-{\sigma }_t){\sigma }_t\\&-2({d(}v^*,v)-{d(}v^*,w_2^*)){\sigma }(F) \\\le & {} Mo(T_1)+2{d(}u,v^*){\sigma }(F)+2({\sigma }(F)-{\sigma }_t){\sigma }_t\\&-2({d(}u,v^*)+{\sigma }(F) -({\sigma }(F)-{\sigma }_t)){\sigma }(F)\\= & {} Mo(T_1)-2{\sigma }_t^2. \end{aligned}$$

So one also has \(Mo(T_1)\le Mo(T)\).

Suppose T is edge central at \(v_1^*v_2^*\), and uv are in \(T_{v^*_1}\) and \(T_{v^*_2}\), respectively. If \(T_1\) is central at \(w^*\), let \(w^*w_1\) be the edge in \(P_{v^*,w^*}\). Put \({\sigma }_t:= |S_T(v^*_2)\setminus (S_T(w^*)\cup V_{P_{v^*_2,w_1}})|\). Then \({\sigma }_t+|P_{v^*_2,w_1}|<{\sigma }(F)\), since \((|T|-{\sigma }_T(v_2))\ge {n}/2\) (because T is edge central at \(v_1^*v_2^*\)) and \({\sigma }_{T_1}(w_1)\le ({n}-2)/2\) (because \(T_1\) is central at \(w^*\)). Note that

$$\begin{aligned} \begin{array}{lllllll} \phi _1(w^*w_1)&{}=&{}{n}-2{\sigma }_{T_1}(w_1)\\ &{}=&{}{n}-2[\frac{{n}}{2}-{\sigma }_T(F) +({\sigma }_t+|P_{v^*_2,w_1}|)]\\ &{}=&{}2[{\sigma }_T(F) -({\sigma }_t+|P_{v^*_2,w_1}|)]\\ &{}=&{}2[{\sigma }_T(F) -({\sigma }_t+{d(}v^*_1,w^*)-1)].\end{array} \end{aligned}$$

If \(e\in E_{P_{v_1^*,w^*}}\), then

$$\begin{aligned} \begin{array}{lllllll} \phi _1(e)&{}\le &{}\phi (w^*w_1)+2({\sigma }_t+{d(}e,w^*))\\ &{}=&{}2[{\sigma }_T(F) -({\sigma }_t+{d(}v^*_1,w^*)-1)] +2({\sigma }_t+{d(}e,w^*))\\ &{}=&{}2[{\sigma }_T(F) -({d(}v^*_1,w^*)-1)] +2{d(}e,w^*).\end{array} \end{aligned}$$

If \({\bar{e}}\in E_{P_{v_1^*,w^*}}\), then

$$\begin{aligned} \phi ({\bar{e}})\ge 2{d(}{\bar{e}},v_1^*). \end{aligned}$$

If \(e,{\bar{e}}\in E_{P_{v_1^*,w^*}}\) satisfy \({d(}v^*,e)={d(}w^*,{\bar{e}})\), then

$$\begin{aligned} \begin{array}{lllllll} \phi _1(e)-\phi (\bar{{e}})\le & {} 2[{\sigma }_T(F) -({d(}v^*_1,w^*)-1)].\end{array} \end{aligned}$$

This gives us

$$\begin{aligned} \begin{array}{lllllll} Mo(T_1) &{}\le &{} Mo(T) +2{d(}u,v_1^*){\sigma }(F)+2{d(}v_1^*,w^*)[{\sigma }_T(F) -({d(}v^*_1,w^*)-1)]\\ &{}&{}-2{d(}w^*,v){\sigma }(F)= Mo(T) +2{d(}u,v_1^*){\sigma }(F)+2{d(}v_1^*,w^*)({\sigma }_T(F)\\ &{}&{}-{d(}v^*_1,w^*))\\ &{}&{}+2{d(}v_1^*,w^*)-2({d(}v_2^*,v)-{d(}v_2^*,w^*)){\sigma }(F)\\ &{}\le &{} Mo(T) +2{d(}u,v_1^*){\sigma }(F)+2{d(}v_1^*,w^*)({\sigma }_T(F)\\ &{}&{}-{d(}v^*_1,w^*))+2{d(}v_1^*,w^*)\\ &{}&{}-2({d(}v_1^*,u)+{\sigma }(F)-{d(}v_1^*,w^*)+1){\sigma }(F)\\ &{}=&{} Mo(T) -2({\sigma }(F))^2+2{d(}v_1^*,w^*)(2{\sigma }(F)-{d(}v_1^*,w^*))\\ &{}&{}+2{d(}v_1^*,w^*)-2{\sigma }(F)\\ &{}=&{} Mo(T) -2({\sigma }(F)-{d(}v_1^*,w^*))({\sigma }(F)-{d(}v_1^*,w^*)+1). \end{array} \end{aligned}$$

That is \(Mo(T_1)\le Mo(T)\).

If \(T_1\) is edge central at \(w_1^*w_2^*\) where \({d(}v_1^*,w^*_1)< {d(}v_1^*,w^*_2)\), let \({\sigma }_t= |S_T(v^*_2)\setminus (S_T(w_2^*)\cup V_{P_{v^*_2,w_1^*}})|\). Then \({\sigma }_t+|P_{v^*_2,w_1^*}|={\sigma }(F)\), since \({\sigma }_{T_1}(w^*_1)= {n}/2={\sigma }_T(v^*_1)\). That is \({d(}v_2^*,w_1^*)={\sigma }(F)-{\sigma }_t-1\). If \(e,{\bar{e}}\in E_{P_{v_2^*,w_1^*}}\) satisfy \({d(}v_2^*,e)={d(}w_1^*,{\bar{e}})\), then \(\phi _1(e)\le \phi ({\bar{e}})+2{\sigma }_t\). So

$$\begin{aligned} \begin{array}{lllllll} Mo(T_1)&{}\le &{} Mo(T_1)+2{d(}u,v_1^*){\sigma }(F) +2{d(}v_2^*,w_1^*){\sigma }_t -2{d(}w_2^*,v){\sigma }(F)\\ &{}=&{} Mo(T_1)+2{d(}u,v_1^*){\sigma }(F)+2({\sigma }(F)-{\sigma }_t-1){\sigma }_t\\ &{}&{}-2({d(}v_2^*,v)-{d(}v_2^*,w_2^*)){\sigma }(F) \\ &{}\le &{} Mo(T_1)+2{d(}u,v^*){\sigma }(F)+2({\sigma }(F)-{\sigma }_t-1){\sigma }_t\\ &{}&{}-2[{d(}u,v_1^*)+{\sigma }(F) -({\sigma }(F)-{\sigma }_t)]{\sigma }(F)\\ &{}=&{}Mo(T_1)-2({\sigma }_t+1){\sigma }_t \end{array} \end{aligned}$$

That is \(Mo(T_1)\le Mo(T)\).

This completes the proof of Case 1.

Case 2 \({d(}v)\ge {d(}u)+{\sigma }(F)+1\). By the proof in Case 1, one always has \(Mo(T_1)\le Mo(T)-2{\sigma }(F)\). That is \(Mo(T_1)< Mo(T)\).

This completes our proof. \(\square \)

3 Greatest Mostar Index in \({\mathcal {T}}^{L}\) and \({\mathcal {T}}(\varepsilon ,k)\)

In this section, we prove Theorems 1.1 and 1.2, which determine \({\mathcal {T}}^{L \max }\), \({\mathcal {T}}^{\max }(\varepsilon ,k)\) and their Mostar indices.

Proof of Theorem 1.1

Let \(T\in {\mathcal {T}}^{L\max }\) where L has size \(\varepsilon \) and let \({n}=\varepsilon +1\). Suppose T is not a starlike tree. Then each branch vertex is in some non-pendent segment.

Case 1 T is central at \(v^*\).

If \(v^*\) is a branch vertex (this happens only when \(l_1< {n}/2\)), let \(P_{v^*,w_1}\) be the non-pendent segment with ends \(v^*\) and \(w_1\). Let \(F=(E(w_1)\setminus E_{P_{v^*,w_1}})\). Then \(T(F^-,(v^*)^+)\) is also in \({\mathcal {T}}^L\). Then \(Mo(T(F^-,(v^*)^+))>Mo(T)\) by Lemma 2.1 (i), contradicted to \(T\in {\mathcal {T}}^{L\max }\).

If \(v^*\) is a 2-vertex in some non-pendent segment \(P_{w_1,w_2}\). Then n is odd since T is central, and the branch containing \(w_i\) has \(({n}-1)/2\) vertices for \(i=1,2\). Without loss of generality, suppose \({d(}v^*,w_1)\le {d(}v^*,w_2)\). If both \(w_1\) and \(w_2\) are branch vertices, let \(F=(E(w_2)\setminus E_{P_{v^*,w_2}})\) and \(P_{w_1,w}\) be a segment incident to \(w_1\) where \(w\ne w_2\). Then \(T(F^-,w^+)\) is in \({\mathcal {T}}^L\) and \(Mo(T(F^-,w^+))>Mo(T)\) by Lemma 2.1 (ii), contradicted to \(T\in {\mathcal {T}}^{L\max }\). So \(P_{w_1,w_2}\) is pendent (which implies \(l_1> {n}/2\) and P is the unique segment of length \(l_1\)). Suppose \(w_1\) is a branch vertex without loss of generality. By assumption, there exists a non-pendent segment \(P_{w_1,w_3}\). Let \(F=(E(w_3)\setminus E_{P_{w_1,w_3}})\). Then \(T(F^-,w_1^+)\in {\mathcal {T}}^L\) and \(Mo(T(F^-,w_1^+))>Mo(T)\) by Lemma 2.1 (i), contradicted to \(T\in {\mathcal {T}}^{L\max }\). Thus, T is a starlike tree in this case.

Case 2 T is central at \(e^*\) (then n is even) where \(e^*\) is in some segment \(P_{w_1,w_2}\).

If both \(w_1\) and \(w_2\) are branch vertices, then \(l_1< {n}/2\). Suppose \({d(}w_1,e^*)\le {d(}w_2,e^*)\) without loss of generality. Let \(F=(E(w_2)\setminus E_{P_{v^*,w_2}})\). Then \(T(F^-,w_1^+)\in {\mathcal {T}}^L\) and \(Mo(T(F^-,w_1^+))>Mo(T)\) by Lemma 2.1 (iii), contradicted to \(T\in {\mathcal {T}}^{L\max }\). So P is a pendent segment (which implies \(l_1\ge {n}/2\) and \(P_{w_1,w_2}\) is the unique segment of length \(l_1\)). Suppose \(w_1\) is a branch vertex without loss of generality. By assumption, there exists an non-pendent segment \(P_{w_1,w_3}\). Let \(F=(E(w_3)\setminus E_{P_{w_1,w_3}})\). Then \(T(F^-,w_1^+)\in {\mathcal {T}}^L\) and \(Mo(T(F^-,w_1^+))>Mo(T)\) by Lemma 2.1 (i), contradicted to \(T\in {\mathcal {T}}^{L\max }\). Thus, T is also a starlike tree of L in this case.

So one always has that T is a starlike tree of L.

On the other hand, one has \(Mo(T)= \sum _{i=1}^{k}\sum _{j=1}^{l_i}|{n}-2j|\). So if \(l_1\le {n}/2\), then

$$\begin{aligned} Mo(T)= {n}({n}-1)-2\sum _{i=1}^{k}\sum _{j=1}^{l_i}j. \end{aligned}$$

If \(l_1\ge {n}/2+1\), then

$$\begin{aligned} Mo(T)= \sum _{j=1}^{l_1}|{n}-2j|+ {n}({n}-2)-2\sum _{i=2}^{k}\sum _{j=1}^{l_i}j. \end{aligned}$$

Since \({n}=\varepsilon +1\), one has

$$\begin{aligned} Mo(T)= \left\{ \begin{array}{lllllll} \varepsilon (\varepsilon +1)-2\sum _{i=1}^{k}\sum _{j=1}^{l_i}j, &{}\quad \mathrm{if}\,\,l_1\le (\varepsilon +1)/2; \\ \sum _{j=1}^{l_1}|\varepsilon +1-2j|+ (\varepsilon +1)(\varepsilon -1) -2\sum _{i=2}^{k}\sum _{j=1}^{l_i}j, &{} \quad \mathrm{if}\,\,l_1\ge (\varepsilon +1)/2+1. \end{array} \right. \end{aligned}$$

This completes our proof. \(\square \)

Proof of Theorem 1.2

Suppose \(T\in {\mathcal {T}}^{\max }(\varepsilon ,k)\) (\(3\le k\le \varepsilon \)) and \({n}=\varepsilon +1\), where \(\varepsilon =\alpha k+\beta \), with \(\alpha \), \(\beta \) being nonnegative integers, and \(0\le \beta \le k-1\). Let \(L=(l_1,l_2,{\ldots },l_k)\) be the segment sequence of T, where \(l_i\ge l_j\) whenever \(i<j\). By Theorem 1.1, one has \(T\cong T^L_S\).

Let v be the unique branch vertex and let \(P_{v,w_1}, P_{v,w_k}\), respectively, be the segments of lengths \(l_1\) and \(l_k\) in \(T^L_S\). Assume \(e_1\in E(w_1)\) and let \(T_1=T(e_1^-,w_k^+)\) which is also in \({\mathcal {T}}(\varepsilon ,k)\). If T is edge central at some edge \(e^*\) in \(P_{v,w_1}\), then \({d(}e^*,e_1)=({n}-4)/2\ge {d(}w_k,e^*)\) since \(k\ge 3\). Then \(Mo(T_1)>Mo(T)\) by Lemma 2.1 (iii), contradicted to \(T\in {\mathcal {T}}^{\max }(\varepsilon ,k)\).

If T is central at some vertex \(v^*\) in \((V_{P_{v,w_1}}\setminus \{v\})\), then \({d(}v^*,e_1)=({n}-5)/2\ge {d(}v^*, w_k)\) since \(k\ge 3\) and each branch has exactly \(({n}-1)/2\) vertices. Then \(Mo(T_1)>Mo(T)\) by Lemma 2.1 (ii), contracted to \(T\in {\mathcal {T}}^{\max }(\varepsilon ,k)\). So T is central at v.

If \(l_k\le l_1-2\), then \(Mo(T_1)>Mo(T)\) by Lemma 2.1 (ii), contradicted to \(T\in {\mathcal {T}}^{\max }(\varepsilon ,k)\). Thus, \(T\cong T_S(\varepsilon ,k)\).

On the other hand, by a direct calculation one has

$$\begin{aligned} Mo(T_S(\varepsilon ,k))= & {} (k-\beta )\sum _{i=1}^{\alpha }({n}-2i) +\beta \sum _{i=1}^{\alpha +1}({n}-2i)\\= & {} {n}^2-({n}+\beta )(\alpha +1)\\= & {} (\varepsilon +1)^2-(\varepsilon +\beta +1)(\alpha +1). \end{aligned}$$

This completes our proof. \(\square \)

4 Trees with Least Mostar Indices in \({\mathcal {T}}(\varepsilon ,k)\)

In this section, \({\mathcal {T}}^{\min }(\varepsilon ,k)\) and their Mostar index are completely determined. First, some properties of trees in \({\mathcal {T}}^{L \min }\) are given.

Let \(L=(l_1,l_2,{\ldots },l_k)\) (\(k\ge 5\)) be a segment sequence. A tree is balanced caterpillar-like if replacing each segment with an edge will result a balanced caterpillar. Figure 5 shows examples for balanced caterpillar-like trees.

Fig. 5
figure 5

a The balanced caterpillar-like tree \(T^{L}_{(2, 2, 4, 1,3,1,3)}\) where \(L=(4,3,3,2,2,1,1)\); b the balanced caterpillar-like tree \(T^{L}_{(2, 2, 3, 1,4,1,2,3)}\) where \(L=(4,3,3,2,2,2,1,1)\)

For convenience, a path or a starlike tree with 3 or 4 segments is also called a balanced caterpillar-like tree. Let \({\mathcal {T}}_C^{L}\subseteq {\mathcal {T}}^{L}\) be the caterpillar-like tree set. Let \(T^L_{(l_{i_1}, l_{i_2}, {\ldots }, l_{i_k})}\in {\mathcal {T}}_C^{L}\) with spine path \(P=u_1u_2{\ldots } u_s\) where \(u_{t_j}\) (\(j\in [1,\lfloor k/2\rfloor -1]\) and \(1=t_1< t_2< {\cdots } < t_{\lfloor k/2\rfloor }=s\)) is a 3-vertex, \(u_s\) is a 3-vertex if k is odd or a 4-vertex if k is even, such that the two pendent segments attached at \(u_{t_1}\) have the lengths \(l_{i_1}\) and \(l_{i_2}\), respectively, the segment connecting \(u_{t_{j-1}}\) (\(j\in [2,\lfloor k/2\rfloor ]\)) and \(u_{t_j}\) has the length \(l_{i_{2j-1}}\), the pendent segment attached at \(u_{t_j}\) (\(j\in [2,\lfloor k/2\rfloor -1]\)) has the length \(l_{i_{2j}}\), and the pendent segments attached at \(u_{s}\) have the length \(l_{i_{k-r}}\) (\(r=0,1\) if k is odd or \(r=0,1,2\) if k is even). See Fig. 5a, b.

Lemma 4.1

Let \(T\in {\mathcal {T}}^{L \min }\) with \(L=(l_1,l_2,{\ldots },l_k)\), \(k\ge 3\) and \(l_i\ge l_j\) whenever \(i<j \).

  1. (1)
    • If T is central at \(v^*\), let \(T_{v_1v^*}\) be an arbitrary extended successor subtree. Then, \(T_{v_1v^*}\) is isomorphic to a balanced caterpillar-like tree with \(v^*\) being a leaf. What is more, if there are at least five segments in \(T_{v_1v^*}\), then \(v^*\) is in some pendent segment incident to some spine end of \(T_{v_1v^*}\) of degree 3;

    • If T is edge central at \(v_1^*v_2^*\), let \(T_1'=T[V_{T_{v_1^*}}\cup \{v_2^*\}]\) and \(T_2'=T[V_{T_{v_2^*}}\cup \{v_1^*\}]\). Then \(T_i'\ (i=1,2)\) is isomorphic to a balanced caterpillar-like tree with \(v_1^*v_2^*\) being a pendent edge. What is more, if there are at least five segments in \(T_i'\), then \(v_1^*v_2^*\) is in some pendent segment incident to some spine end of \(T_i'\) of degree 3.

  2. (2)

    Let \(P_{w_{1,1},w_{1,2}}\) and \(P_{w_{2,1},w_{2,2}}\) be two segments of T in a common extended successor subtree where \({d(}w_{i,1})<{d(}w_{i,2})\) and \(l_{x_i}=|E_{P_{w_{i,1},w_{i,2}}}|\ (i=1,2)\).

    • If \(w_{1,2}=w_{2,1}\), then \(l_{x_1}\ge l_{x_2}\).

    • If \(P_{w_{1,1},w_{1,2}}\) and \(P_{w_{2,1},w_{2,2}}\) are both pendent segments with \({d(}w_{1,1})< {d(}w_{2,1}),\) then \(l_{x_1}\le l_{x_2}\).

    • If T is edge central, or is central at a 2-vertex, then the segment containing the (edge) center has the length \(l_1\).

    • If \(k\ge 5\) and T is central at a branch vertex \(v^*\), then \({d(}v^*)\le 4\) with equality only if \(k=6\) and all segments in T have the same length. What is more, if \({d(}v^*)=3\), then \(v^*\) admits exactly one pendent segment length of \(l_k\) and two non-pendent segments.

  3. (3)

    At most one extended successor subtree of T has a vertex of degree 4.

Proof

(1)  When T is edge central, it is sufficient to show the conclusion holds for \(T_1'\). Let \({\hat{T}}=T_{v_1v^*}\) or \(T_1'\), and let \(a=v^*\) or \(v_1^*v_2^*\). The conclusion holds easily if \({\hat{T}}\) contains at most four segments. So we consider that \({\hat{T}}\) contains at least five segments in what follows.

Let v be a branch vertex in \({\hat{T}}\) (then \(v\ne v^*\) or \(v_2^*\)). If v is incident to at least two non-pendent segments (\(P_{v,w_1}\) and \(P_{v,w_2}\)) in T where \(w_1,w_2\in S(v)\), then without loss of generality, assume that \({d(}w_1)\le {d(}w_2)\). Let \(F= (E(w_1)-E_{P_{v,w_1}})\) and w be a leaf in \(S(w_2)\). Then \(T(F^-,w^+)\in {\mathcal {T}}^{L}\) and \(Mo(T(F^-,w^+))<Mo(T)\) by Lemma 2.1 (i), contradicted to \(T\in {\mathcal {T}}^{L \min }\).

Next we consider that v is incident to exactly one non-pendent segment \(P_{v,w_1}\) in T such that \(w_1\in S(v)\). If \({d(}v)\ge 4\), let \(e\in (E(v)-E_{P_{v,w_1}}-E_{P_{v^*,v}})\). Then \(T(e^-,w_1^+)\in {\mathcal {T}}^{L}\), and \(Mo(T(e^-,w_1^+))< Mo(T)\) by Lemma 2.1 (i), contradicted to \(T\in {\mathcal {T}}^{L \min }\). So \({d(}v)=3\).

Now we consider that there does not exist branch vertex in \((S(v)\setminus \{v\})\). Let \(P_{v,w_1}\) be a pendent segment such that \(w_1\in S(v)\). If \({d(}v)\ge 5\), let \(F=\{e_1,e_2\}\) where \(e_1,e_2\in (E(v)-E_{P(v)}-E_{P_{v,w_1}})\). Then \(T(F^-,w_1^+)\in {\mathcal {T}}^{L}\), and \(Mo(T(F^-,w_1^+))< Mo(T)\) by Lemma 2.1 (i), a contradiction. So \({d(}v)\le 4\).

Thus, (1) holds.

(2) Suppose \(w_{1,2}=w_{2,1}\). Then \(P_{w_{1,1},w_{1,2}}\) is a non-pendent segment. If \(l_{x_1}< l_{x_2}\), then choose \(w\in V_{P_{w_{2,1},w_{2,2}}}\) such that \({d(}w_{1,1},w)=l_{x_2}\). Put \(F:= (E(w_{1,2})-E_{P_{w_{1,1},w_{2,2}}})\). Then \(T(F^-,w^+)\in {\mathcal {T}}^{L}\), and \(Mo(T(F^-,w^+))< Mo(T)\) by Lemma 2.1 (i), contradicted to \(T\in {\mathcal {T}}^{L \min }\). So \(l_{x_1}\ge l_{x_2}\) and the first item holds.

Suppose both \(P_{w_{1,1},w_{1,2}}\) and \(P_{w_{2,1},w_{2,2}}\) are pendent segments with \({d(}w_{1,1})< {d(}w_{2,1})\). If \(l_{x_1}> l_{x_2}\), then choose \(e\in E_{P_{w_{1,1},w_{1,2}}}\) such that \({d(}w_{1,1},e)=l_{x_2}\). Then \(T(e^-,w_{2,2}^+)\in {\mathcal {T}}^{L}\), and \(Mo(T(e^-,w_{2,2}^+))< Mo(T)\) by Lemma 2.1 (i), contradicted to \(T\in {\mathcal {T}}^{L \min }\). So \(l_{x_1}\le l_{x_2}\) and the second item holds.

Suppose T is edge central or central at a 2-vertex. Let \(P_{w_1,w_2}\) be the segment containing the (edge) center which has length \(l_{x_1}\). If \(l_1\ge {n}/2\), then it is easy to see \(|E_{P_{w_1,w_2}}|=l_1\). Suppose \(l_1< {n}/2\). Then \(P_{w_1,w_2}\) is a non-pendent segment. Let \(P_{w_i,w_{i+2}}\) (\(i=1,2\)) be the segment other than \(P_{w_1,w_2}\), which has the greatest length among all segments incident to \(w_i\). Let \(l_{z_i}=|E_{P_{w_i,w_{i+2}}}|\) (\(i=1,2\)). If \(l_{x_1}<l_{z_1}\), then choose a vertex w in \(P_{w_1,w_{3}}\) such that \({d(}w,w_2)=l_{z_1}\) and let \(F= (E(w_1)-E_{P_{w_1,w_{3}}}-E_{P_{w_1,w_2}})\). Then \(T(e^-,w^+)\in {\mathcal {T}}^{L}\), and \(Mo(T(e^-,w^+))< Mo(T)\) by Lemma 2.1 (i), contradicted to \(T\in {\mathcal {T}}^{L \min }\). So \(l_{x_1}\ge l_{z_1}\). Similarly, one has \(l_{x_1}\ge l_{z_2}\). So \(l_{x_1}=l_1\) and the third item holds.

For the fourth item, suppose \(k\ge 5\) and T is central at a branch vertex \(v^*\).

If \({d(}v^*)\ge 5\), then choose \(v_1,v_2,v_3,v_4,v_5\in N(v^*)\) such that \(|T_{v_1}|\le |T_{v_2}|\le |T_{v_3}|\le |T_{v_4}|\le |T_{v_5}|\). Thus, \(|T_{v_1}|+|T_{v_3}|<{n}/2\). Let \(P_{v^*,w_i}\) (\(i=1,2,3,4,5\)) be the segment in \(T_{v^*v_i}\) incident to \(v^*\). Let \(T_1=T(v^*v_1^-,w_3^+)\) and \(T_2=T_1(v^*v_2^-,w_3^+)\). Then \(T_1\) is also central at \(v^*\), \(T_2\in {\mathcal {T}}^L\) and \(Mo(T_1)<Mo(T)\) by Lemma 2.1 (ii). If \(w_3\) is a branch vertex, then \(T_1\in {\mathcal {T}}^L\), contradicted to \(T\in {\mathcal {T}}^{L \min }\). If \(w_3\) is a leaf, then \({d(}v^*,w_3)=|T_{v_3}|\ge {d(}v^*,w_2)\), which implies \(Mo(T_2)\le Mo(T_1)<Mo(T)\) by Lemma 2.2 (iii), also contradicted to \(T\in {\mathcal {T}}^{L \min }\). So \({d(}v^*)\le 4\).

Case 1 \({d(}v^*)=4\). Then, let \(N(v^*)=\{v_1,v_2,v_3,v_4\}\) and \(P_{v^*,w_i}\) (\(i=1,2,3,4\)) be the segment of length \(l_{x_i}\) in \(T_{v^*v_i}\) incident to \(v^*\). Suppose \({\sigma }(v_1)\le {\sigma }(v_2)\le {\sigma }(v_3)\le {\sigma }(v_4)\). Then \({\sigma }(v_1)+{\sigma }(v_2)\le {\sigma }(v_3)+{\sigma }(v_4)\) and \({\sigma }(v_1)+{\sigma }(v_3)\le {\sigma }(v_2)+{\sigma }(v_4)\). If \(w_3\) is a branch vertex, then \(T(v^*v_1^-,w_3^+)\in {\mathcal {T}}^L\) is also central at \(v^*\), and \(Mo(T(v^*v_1^-,w_3^+))< Mo(T)\) by Lemma 2.1 (ii), contradicted to \(T\in {\mathcal {T}}^{L \min }\). So \(w_3\) is a leaf. By a similar discussion, one concludes that \(w_i\) (\(i=1,2\)) is also a leaf. So \(w_4\) is a branch vertex since \(k\ge 5\).

If \(l_{x_4}<l_{x_3}\), suppose w is a vertex in \(P_{v^*,w_3}\) such that \({d(}w_4,w)=l_{x_3}\). Let \(F=\{v^*v_1,v^*v_2\}\). Then \(T(F^-,w^+)\in {\mathcal {T}}^L\) and \(Mo(T(F^-,w^+))< Mo(T)\) by Lemma 2.2 (ii), contradicted to \(T\in {\mathcal {T}}^{L \min }\). So \(l_{x_4}\ge l_{x_3}\).

Let \(P_{w_4,w_{4,1}}\) and \(P_{w_4,w_{4,2}}\) be two segments of length \(l_{4,1}\) and \(l_{4,2}\), respectively, which is incident to \(w_4\), where \(w_{4,i}\ne v^*\) (\(i=1,2\)). Without loss of generality, suppose \(P_{w_4,w_{4,1}}\) is pendent and \(l_{4,1}\le l_{4,2}\), by the first and the second item of Lemma 4.1 (2). If \(l_{4,1}<l_{x_3}\), let e be the edge in \(P_{v^*,w_3}\) such that \({d(}v^*,e)=l_{4,1}\). Then \(T(e^-,w_{4,1}^+)\in {\mathcal {T}}^L\) and \(Mo(T(e^-,w_{4,1}^+))< Mo(T)\) by Lemma 2.2 (iii), contradicted to \(T\in {\mathcal {T}}^{L \min }\). Then \(l_{4,1}\ge l_{x_3}\), and \(l_{4,1}+l_{4,2}+l_{x_4}\ge l_{x_1}+l_{x_2}+l_{x_3}\), which implies \(k=6\) and all the segments in T have the same length, since T is central at \(v^*\).

Case 2 \({d(}v^*)=3\). Then let \(N(v^*)=\{v_1,v_2,v_3\}\) and \(P_{v^*,w_i}\) (\(i=1,2,3\)) be the segment of length \(l_{x_i}\) in \(T_{v^*v_i}\) incident to \(v^*\). Suppose \({\sigma }(v_1)\le {\sigma }(v_2)\le {\sigma }(v_3)\). If \(w_1\) is a branch vertex, let \(e\in (E(w_1)\setminus E_{P_{v^*,w_1}})\). Then \(T(v^*v_2,e)\in {\mathcal {T}}^L\) and \(Mo(T(v^*v_2,e))< Mo(T)\) by Lemma 2.2 (ii), contradicted to \(T\in {\mathcal {T}}^{L \min }\). So \(w_1\) is a leaf.

If \(w_2\) is also a leaf, then \(w_3\) is a branch vertex since \(k\ge 5\). If \(l_{x_3}<l_{x_2}\), choose a vertex w in \(P_{v^*,w_2}\) such that \({d(}w_3,w)=l_{x_2}\). Then \(T(v^*v_1^-,w^+)\in {\mathcal {T}}^L\) and \(Mo(T(v^*v_1^-,w^+))<Mo(T)\) by Lemma 2.2 (ii), contradicted to \(T\in {\mathcal {T}}^{L \min }\). So \(l_{x_3}\ge l_{x_2}\).

Let \(P_{w_3,w_{3,1}}\) and \(P_{w_3,w_{3,2}}\) be two segments of length \(l_{3,1}\) and \(l_{3,2}\), respectively, which is incident to \(w_3\), where \(w_{3,i}\ne v^*\) (\(i=1,2\)). Without loss of generality, suppose \(P_{w_3,w_{3,1}}\) is pendent and \(l_{3,1}\le l_{3,2}\), by the first and the second item of Lemma 4.1 (2). If \(l_{3,1}<l_{x_2}\), let e be the edge in \(P_{v^*,w_2}\) such that \({d(}v^*,e)=l_{3,1}\). Then \(T(e^-,w_{3,1}^+)\in {\mathcal {T}}^L\) and \(Mo(T(e^-,w_{3,1}^+))<Mo(T)\) by Lemma 2.2 (iii), contradicted to \(T\in {\mathcal {T}}^{L \min }\). So \(l_{3,1}\ge l_{x_2}\). Then \(l_{3,1}+l_{3,2}+l_{x_3}> l_{x_1}+l_{x_2}\), contracted to the fact that T is central at \(v^*\). So \(w_2\) is a branch vertex.

If \(l_{x_2}<l_{x_1}\), choose w be the vertex in \(P_{v^*,w_1}\) with \({d(}w_2,w)=l_{x_1}\). Then \(T(v^*v_3^-,w^+)\in {\mathcal {T}}^L\) and \(Mo(T(v^*v_3^-,w^+))<Mo(T)\) by Lemma 2.2 (ii), contradicted to \(T\in {\mathcal {T}}^{L \min }\). Then, \(l_{x_2}\ge l_{x_1}\). Let \(P_{w_2,w_{2,1}}\) and \(P_{w_2,w_{2,2}}\) be two segments of length \(l_{2,1}\) and \(l_{2,2}\), respectively, which is incident to \(w_2\), where \(w_{2,i}\ne v^*\) (\(i=1,2\)). Without loss of generality, suppose \(P_{w_2,w_{2,1}}\) is pendent and \(l_{2,1}\le l_{2,2}\), by the first and the second item of Lemma 4.1 (2). If \(l_{2,1}<l_{x_1}\), let e be the edge in \(P_{v^*,w_1}\) such that \({d(}v^*,e)=l_{2,1}\). Then \(T(e^-,{w^+_{2,1}})\in {\mathcal {T}}^L\) and \(Mo(T(e^-,{w^+_{2,1}}))<Mo(T)\) by Lemma 2.2 (iii), contradicted to \(T\in {\mathcal {T}}^{L \min }\). So \(l_{2,1}\ge l_{x_1}\). So \(l_{x_1}=l_k\).

Thus, we have (2) holds.

(3) By (1) and (2), if \(k\le 6\) the conclusion holds directly. Suppose \(k\ge 7\). Let \({\tilde{T}}_1\) and \({\tilde{T}}_2\) be arbitrary two extended successor subtrees of T, and a be the (edge) center of T. By (1), there is at most one 4-vertex in \({\tilde{T}}_i\) (\(i=1,2\)) which would be the end of the spine in \({\tilde{T}}_i\) which is at a longer distance from a. If there are two 4-vertices \(w_1\) and \(w_2\) in \({\tilde{T}}_1\) and \({\tilde{T}}_2\), respectively, then the (edge) center is in some non-pendent segment by (2).

For \({i=1,2;}\ j=1,2,3\), let \(P_{w_i,w_{i,j}}\) be the pendent segment incident to \(w_i\) whose length is \(l_{i,j}\). Without loss of generality, suppose \(l_{i,j_1}\le l_{i,j_2}\) (\(i=1,2\)) whenever \(j_1< j_2\), and \({d(}w_{1,1},a)\le {d(}w_{2,3},a)\). Let \(e_{i,j}\) (\(i=1,2; j=1,2,3\)) be the edge in \(P_{w_i,w_{i,j}}\) which is incident to \(w_i\). Let \(T_1=T(e_{2,2}^-,w_{2,3}^+)\) and \(T_2=T_1(e_{1,1}^-,w_{2,3}^+)\). Then \(T_2\in {\mathcal {T}}^L\) and a is also the (edge) center of \(T_1\). Note that \(Mo(T_2)\le Mo(T_1)\) by Lemma 2.2 (iii), and \(Mo(T_1)<Mo(T)\) by Lemma 2.1 (i) or Lemma 2.2 (ii), contradicted to \(T\in {\mathcal {T}}^{L \min }\). So there is at most one extended successor subtree of T having a vertex of degree 4. Thus, (3) also holds. \(\square \)

Corollary 4.2

Let T be a tree in \({\mathcal {T}}^{L \min }\) with \(L=(l_1,l_2,{\ldots },l_k)\) and \(k\ge 5\). Then T is caterpillar-like tree, where there is a non-pendent segment of length \(l_1\) in the spine which contains the center or edge center. What is more, let \(P=u_1u_2{\ldots } u_s\) be the spine of T, and \(u_{t_{j}}\) \(( j\in [1,\lfloor (k-1)/2\rfloor ])\) be a branch vertex). Then

  1. (1)

    Suppose T is central at a branch vertex \(u_{t_\lambda }\) \({(}\lambda \in [1, k]{)}\). Then \({d(}u_{t_\lambda })=4\) if and only if \(k=6\) and all segments in T have the same length. If \({d(}u_{t_\lambda })=3\), then \(k\ge 7\), T admits exactly two non-pendent segments, \( l_{i_{2\lambda }}\le l_{i_{2\lambda -2}}\le l_{i_{2\lambda -4}}\le {\cdots }\le l_{i_2}\le l_{i_1} \le l_{i_3}\le {\cdots }\le l_{i_{2\lambda -1}}\), and \(l_{i_{2\lambda }}\le l_{i_{2\lambda +2}}\le l_{i_{2\lambda +4}}\le {\cdots }\le l_{i_{k-1}}\le l_{i_k} \le l_{i_{k-2}}\le {\cdots }\le l_{i_{2\lambda +3}}\le l_{i_{2\lambda +1}}\) if k is odd or \(l_{i_{2\lambda }}\le l_{i_{2\lambda +2}}\le l_{i_{2\lambda +4}}\le {\cdots }\le l_{i_{k-2}}\le l_{i_{k-1}}\le l_{i_k} \le l_{i_{k-3}}\le {{\cdots }}\le l_{i_{2\lambda +3}}\le l_{i_{2\lambda +1}}\) if k is even.

  2. (2)

    Suppose T is central at a 2-vertex \(u_\lambda \), or T is edge central at \(u_\lambda u_{\lambda +1}\). Let \(y=\max \{{{j}}|{t_{j}}\le \lambda \}\). Then \(l_{i_{2y}}\le l_{i_{2y-2}}\le {\cdots }\le l_{i_2}\le l_{i_1} \le l_{i_3}\le {\cdots }\le l_{i_{2y-1}}\le l_{i_{2y+1}}\), and \(l_{i_{2y+2}}\le l_{i_{2y+4}}\le {\cdots }\le l_{i_{k-1}}\le l_{i_k} \le l_{i_{k-2}}\le {\cdots }\le l_{i_{2y+3}}\le l_{i_{2y+1}}\) if k is odd or \(l_{i_{2y+2}}\le l_{i_{2y+4}}\le {\cdots }\le l_{i_{k-2}}\le l_{i_{k-1}}\le l_{i_k} \le l_{i_{k-3}}\le {\cdots }\le l_{i_{2y+3}}\le l_{i_{2y+1}}\) if k is even.

Proof

If \(k=3\) or 4, then T is a caterpillar-like tree by definition. If \(k\ge 5\) and T is edge central or central with the center being a 2-vertex, then T is a caterpillar-like tree by Lemma 4.1 (1) and (3); if \(k\ge 5\) and T is central with the center being a branch vertex, then T is a caterpillar-like tree by Lemma 4.1 (1), (2) and (3).

For the rest conclusions in Corollary 4.2, if T is edge central or central at a 2-vertex, then they hold directly by the first, second and third items of Lemma 4.1 (2). If T is central at a branch vertex, then they hold directly by the first, second and fourth items of Lemma 4.1 (2). \(\square \)

Proof of Theorem 1.3

Let \(T\in {\mathcal {T}}^{\min }(\varepsilon ,k)\) (\(3\le k\le \varepsilon \)) and \({n}=\varepsilon +1\). Let \(L=(l_1,l_2,{\ldots },l_k)\) be the segment sequence of T, where \(l_i\ge l_j\) whenever \(i<j\). Let a be the (edge) center of T.

If \((\varepsilon ,k)=(3,3), (4,3), (4,4)\) or (5, 4), then \({\mathcal {T}}(\varepsilon ,k)\) has a unique tree. Suppose \(k=3\) and \(\varepsilon \ge 5\), or \(k=4\) and \(\varepsilon \ge 6\). Then \(l_1\ge 2\). Let \(P_{v,w_i}\) (\(i=1,2,3,4\)) be a segment of length \(l_i\), \(w_iw'_i\) be the pendent edge incident to \(w_i\) and \(e_i\in (E_{P_{v,w_i}}\cap E(v))\). Then \(P_{v,w_1}\) contains the (edge) center. Let \(F=(E(v)\setminus \{e_1,e_2\})\). If \(l_2\ge 2\), then \(T(F^-,w_2'^+)\in {\mathcal {T}}(\varepsilon ,k)\) and \(Mo(T(F^-,w_2'^+))<Mo(T)\) by Lemma 2.1 (i) or Lemma 2.2 (ii), contradicted to \(T\in {\mathcal {T}}^{\min }(\varepsilon ,k)\). So \(l_2=1\) and \(T\cong T_C(\varepsilon ,k)\).

Suppose \(k\ge 5\). Then T is a balanced caterpillar-like tree satisfying Corollary 4.2.

If \({n}=k+1\), then T is the unique tree \(T_C(\varepsilon ,k)\) in \({\mathcal {T}}_C^L\) where \(L=(1,1,{\ldots },1)\) of length k.

If \({n}=k+2\), then \((k-1)\) segments have a length one, and the rest segment \(w_1w_2w_3\) of length 2 contains the (edge) center of T by Corollary 4.2. Without loss of generality, suppose \(\zeta (w_1)\le \zeta (w_3)\), where \(\zeta (w_i)\) (\(i=1,3\)) is the vertex number of the component in \((T-\{w_1w_2,w_2w_3\})\) that contains \(w_i\). Then T is central at \(w_2\) if and only if \(\zeta (w_1)=\zeta (w_3)\) and \(k=4t+1\) (\(t\ge 1\)); T is edge central at \(w_2w_3\) if and only if \(\zeta (w_1)=\zeta (w_3)-1\) and k is an even integer at least 6; T is central at \(w_3\) if and only if \(\zeta (w_1)=\zeta (w_3)-2\) and \(k=4t+3\) (\(t\ge 1\)). That is \(T\cong T_C(\varepsilon ,k)\).

If \({n}\ge k+3\), then first we have the following claims.

Claim 1

Suppose \({n}\ge k+3\) with \(k\ge 5\). Let \(T_{b}\) be an extended successor subtree of T. If \(T_{b}\) contains at least one branch vertex other than the center, then each segment of T in \(T_{b}\) other than the one which contains the (edge) center has the length one.

Proof

Let \(w_1\) be one branch vertex other than the center, such that \({d(}w_1)\) is minimal. Let \(P_{w_1,w_2}\) be the longest segment incident to \(w_1\) in \(T_{b}\) such that \(V_{P_{w_1,w_2}}\subseteq S(w_1)\) and \(w_2w'_2\in E_{P_{w_1,w_2}}\). Then \(P_{w_1,w_2}\) is the longest segment in \(T_{b}\) other than the one containing the (edge) center, by Corollary 4.2. Let \(P_{w_1,w_3}\) be the other segment such that \(V_{P_{w_1,w_3}}\subseteq {\sigma }(w_1)\) and \(w_1w'_3\in E_{P_{w_1,w_3}}\). If \(|E_{P_{w_1,w_2}}|\ge 2\), then \(T(w_1w_3'^-,w'^+_2)\in {\mathcal {T}}(\varepsilon ,k)\) and \(Mo(T(w_1w_3'^-,w'^+_2))< Mo(T)\) by Lemma 2.1 (i), contradicted to \(T\in {\mathcal {T}}^{\min }(\varepsilon ,k)\). This implies \( |E_{P_{w_1,w_2}}|=1\) and so all segments in \(T_{b}\) other than the one containing the (edge) center are of length one. \(\square \)

Claim 2

Suppose T is central at \(v^*\), \(k\ge 5\) and \({n}\ge k+3\). Then \({d(}v^*)=2\).

Proof

By the proof of Corollary 4.2, if \(v^*\) is incident to exactly one non-pendent segment, then \(k=6\), \({d(}v^*)=4\) and each segment has a common length l where \(l\ge 2\) since \({n}\ge k+3\). However, let P and \(P'\) be two pendent segments incident to \(v^*\), and let e be a pendent edge in P and w be a leaf in \(P'\). Then \(T(e^-,w^+)\in {\mathcal {T}}(\varepsilon ,k)\) and \(Mo(T(e^-,w^+))<Mo(T)\) by Lemma 2.1 (ii), contradicted to \(T\in {\mathcal {T}}^{\min }(\varepsilon ,k)\). So \(v^*\) is incident to two non-pendent segments (supposed to be \(P_{v^*,w_1}\) and \(P_{v^*,w_2}\) of length \(l_{1}\) and \(l_{2}\), respectively, by Corollary 4.2). Then \(k\ge 7\).

Let \(P_{v^*,w_3}=v^*w_3\) be the pendent segment of length one, by Claim 1 and Corollary 4.2. Let \(w_1w\in E_{P_{v^*,w_1}}\). Then \(T(v^*w_3^-,w^+)\in {\mathcal {T}}(\varepsilon ,k)\). Let \(T_{v_i}\) (\(i=1,2\)) be the branch containing \(w_i\). Note that one has either \(l_1\ge 3\) holds, or \(l_1, l_2\ge 2\) holds. If \(l_1\ge 3\), then \(Mo(T(v^*w_3^-,{w^+}))<Mo(T)\) by Lemma 2.2 (iii), contradicted to \(T\in {\mathcal {T}}^{\min }(\varepsilon ,k)\). If \(l_1\ge 2\) and \(l_2\ge 2\), without loss of generality, suppose \({\sigma }(v_1)\le {\sigma }(v_2)\). Then again, \(Mo(T(v^*w_3^-,w^+))<Mo(T)\) by Lemma 2.2 (iii), also contradicted to \(T\in {\mathcal {T}}^{\min }(\varepsilon ,k)\). \(\square \)

By Claim 2 and Corollary 4.2, T is either edge central at some edge in a non-pendent segment of length \(l_1\), or central at some 2-vertex in a non-pendent segment of length \(l_1\). So by Claim 1, each segment other than the non-pendent segment containing the center or edge center has a length one. That is, \(L=(l_1,1,1,{\ldots },1)\).

Let \(P=w_1w_2{\ldots } w_{{n}-k+1}\) be the non-pendent segment containing the (edge) center. Let \(\zeta (w_i)\) (\(i=1,{n}-k+1\)) be the number of vertices in the connected component in \((T-E_{P})\) containing \(w_i\). Without loss of generality, suppose \(\zeta (w_1)\le \zeta (w_{{n}-k+1})\). Note that there is at least one branch vertex in each of \(S(v_1)\) and \(S(w_{{n}-k+1})\). If \(k=5,\) 6 or 7, then \(T\cong T_C(\varepsilon ,k)\). If \(k\ge 8\), then \({d(}w_{{n}-k+1})=3\). Let \(e_1\) be the pendent edge incident to \(w_{{n}-k+1}\) and \(w_1w_2\in E_{P_{w_1,a}}\). Then \(T_1=T(e_1^-,w_2^+)\in {\mathcal {T}}(\varepsilon ,k)\).

If \(k=4t+1\) (\(t\ge 2\)), then \(\zeta (w_1)= \zeta (w_{{n}-k+1})\). Otherwise, one has \(\zeta (w_1)\ge \zeta (w_{{n}-k+1})-4z\) for some \(z\ge 1\) which implies \({d(}w_1)\le {d(}w_{{n}-k+1})+4\) (that is \({d(}w_2)\le {d(}w_{{n}-k+1})+3\)). When \({n}\le k+4\), it is a contradiction to Claim 2; When \({n}\ge k+5\), \(Mo(T_1)<Mo(T)\) by Lemma 2.2 (iii), contradicted to \(T\in {\mathcal {T}}^{\min }(\varepsilon ,k)\).

If \(k=4t+3\) (\(t\ge 2\)), then \(\zeta (w_1)= \zeta (w_{{n}-k+1})-2\). Otherwise, one has \(\zeta (w_1)\ge \zeta (w_{{n}-k+1})-4z-2\) for some \(z\ge 1\) which implies \({d(}w_1)\le {d(}w_{{n}-k+1})+6\) (that is \({d(}w_2)\le {d(}w_{{n}-k+1})+5\)). When \({n}\le k+5\), it is a contradiction to Claim 2; when \({n}\ge k+6,\) \(Mo(T_1)<Mo(T)\) by Lemma 2.2 (iii), contradicted to \(T\in {\mathcal {T}}^{\min }(\varepsilon ,k)\).

If \(k=2t\) (\(t\ge 4\)), then \(\zeta (w_1)= \zeta (w_{{n}-k+1})-1\). Otherwise, one has \(\zeta (w_1)\ge \zeta (w_{{n}-k+1})-2z-1\) for some \(z\ge 1\) which implies \({d(}w_1)\le {d(}w_{{n}-k+1})+3\) (that is \({d(}w_2)\le {d(}w_{{n}-k+1})+2\)). When \({n}\le k+3\), it is a contradiction to Claim 2; when \({n}\ge k+4\), \(Mo(T_1)<Mo(T)\) by Lemma 2.2 (iii), contradicted to \(T\in {\mathcal {T}}^{\min }(\varepsilon ,k)\).

Thus, \(T\cong T_C(\varepsilon ,k)\) also holds when \(k\ge 5\) and \({n}\ge k+3\).

On the other hand,

  1. (1)

    If \(k=3\), then

    $$\begin{aligned} Mo(T)=2({n}-2)+\sum _{i=1}^{{n}-3}|{n}-2(2i-1)|= \left\lfloor \frac{({n}-1)^2}{2}\right\rfloor +2. \end{aligned}$$
  2. (2)

    If \(k=4\) and \({n}=5\), one has \(Mo(T)= 12;\) If \(k=4\) and \({n}\ge 6\), then

    $$\begin{aligned} Mo(T)=3({n}-2)+\sum _{i=1}^{{n}-4}|{n}-2(2i-1)| = \left\lfloor \frac{({n}-1)^2}{2}\right\rfloor +6. \end{aligned}$$
  3. (3)

    If \(k=4t+1\) (\(t\ge 1\)) and \(({n}-k)\) is odd, then

    $$\begin{aligned} Mo(T)= & {} 2t\cdot ({n}-2)+2\sum _{i=1}^t [{n}-2(2i-1)]+2\sum _{i=1}^{\frac{{n}-k-1}{2}}(2i)\\ {}= & {} \frac{{n}^2}{2}-{n}+\frac{(k-1)^2}{4}. \end{aligned}$$

    If \(k=4t+1\) (\(t\ge 1\)) and \(({n}-k)\) is even, then

    $$\begin{aligned} Mo(T)= & {} 2t\cdot ({n}-2)+2\sum _{i=1}^t [{n}-2(2i-1)]+2\sum _{i=1}^{\frac{{n}-k}{2}}(2i-1)\\ {}= & {} \frac{{n}^2 +1}{2}-{n}+\frac{(k-1)^2}{4}. \end{aligned}$$
  4. (4)

    If \(k=4t+3\) (\(t\ge 1\)) and \(({n}-k)\) is odd, one has

    $$\begin{aligned} Mo(T)= & {} (2t+1)\cdot ({n}-2)+2\sum _{i=1}^{t+1}[{n}-2(2i-1)] +\sum _{i=1}^{\frac{{n}-k-3}{2}}(2i) +\sum _{i=1}^{\frac{{n}-k-1}{2}}(2i)\\ {}= & {} \frac{{n}^2}{2}-{n}+\frac{(k-1)^2}{4}+1. \end{aligned}$$

    If \(k=4t+3\) (\(t\ge 1\)) and \(({n}-k)\) is even, one has

    $$\begin{aligned} Mo(T)= & {} (2t+1)\cdot ({n}-2)+2\sum _{i=1}^{t+1}[{n}-2(2i-1)]+\sum _{i=1}^{\frac{{n}-k-2}{2}}(2i-1) +\sum _{i=1}^{\frac{{n}-k}{2}}(2i-1)\\ {}= & {} \frac{{n}^2+1}{2}-{n}+\frac{(k-1)^2}{4}+1. \end{aligned}$$
  5. (5)

    If \(k=4t+2\) (\(t\ge 1\)) and \(({n}-k)\) is odd, then

    $$\begin{aligned} Mo(T)= & {} (2t+2)\cdot ({n}-2)+\sum _{i=1}^{t}[{n}-2(2i-1)]+\sum _{i=2}^{t}[{n}-2(2i)]\\&+\sum _{i=1}^{\frac{{n}-k+1}{2}}(2i-1) +\sum _{i=1}^{\frac{{n}-k-1}{2}}(2i-1) \\= & {} \frac{{n}^2+1}{2}-{n}+\frac{(k-1)^2+7}{4}. \end{aligned}$$

    If \(k=4t+2\) (\(t\ge 1\)) and \(({n}-k)\) is even, then

    $$\begin{aligned} Mo(T)= & {} (2t+2)\cdot ({n}-2)+\sum _{i=1}^{t}[{n}-2(2i-1)]+\sum _{i=2}^{t}[{n}-2(2i)]\\&+\sum _{i=1}^{\frac{{n}-k+2}{2}}(2i) +\sum _{i=1}^{\frac{{n}-k-2}{2}}(2i) \\= & {} \frac{{n}^2}{2}-{n}+\frac{(k-1)^2+7}{4}. \end{aligned}$$
  6. (6)

    If \(k=4t+4\) (\(t\ge 1\)) and \(({n}-k)\) is odd, then

    $$\begin{aligned} Mo(T)= & {} (2t+3)\cdot ({n}-2)+\sum _{i=1}^{t+1}[{n}-2(2i-1)]+\sum _{i=2}^{t}[{n}-2(2i)]\\&+\sum _{i=1}^{\frac{{n}-k+1}{2}}(2i-1) +\sum _{i=1}^{\frac{{n}-k-1}{2}}(2i-1) \\= & {} \frac{{n}^2+1}{2}-{n}+\frac{(k-1)^2+7}{4}. \end{aligned}$$

    If \(k=4t+4\) (\(t\ge 1\)) and \(({n}-k)\) is even, then

    $$\begin{aligned} Mo(T)= & {} (2t+3)\cdot ({n}-2)+\sum _{i=1}^{t+1}[{n}-2(2i-1)]+\sum _{i=2}^{t}[{n}-2(2i)]\\&+\sum _{i=1}^{\frac{{n}-k}{2}}(2i) +\sum _{i=1}^{\frac{{n}-k-2}{2}}(2i)\\= & {} \frac{{n}^2}{2}-{n}+\frac{(k-1)^2+7}{4}. \end{aligned}$$

So for \(3\le k\le \varepsilon \), one has

$$\begin{aligned} Mo(T)=\left\{ \begin{array}{lllllll} \lfloor \frac{({n}-1)^2}{2}\rfloor +2, &{} \quad \hbox {if } \quad k=3; \\ 12, &{}\quad \hbox {if }\quad k=4 \, \hbox {and }\, {n}= 5; \\ \lfloor \frac{({n}-1)^2}{2}\rfloor +6, &{} \quad \hbox {if }\quad k=4 \, \hbox {and }\, {n}\ge 6 ; \\ \lceil \frac{{n}^2}{2}\rceil -{n}+\frac{(k-1)^2}{4}, &{} \quad \hbox {if } \quad k=4t+1 (t\ge 1); \\ \lceil \frac{{n}^2}{2}\rceil -{n}+\frac{(k-1)^2}{4}+1, &{}\quad \hbox {if }\quad k=4t+3 (t\ge 1); \\ \lceil \frac{{n}^2}{2}\rceil -{n}+\frac{(k-1)^2+7}{4}, &{}\quad \hbox {if }\quad k=2t (t\ge 3). \end{array} \right. \end{aligned}$$

That is,

$$\begin{aligned} Mo(T)=\left\{ \begin{array}{lllllll} \lfloor \frac{\varepsilon ^2}{2}\rfloor +2, &{} \quad \hbox {if }\quad k=3; \\ 12, &{} \quad \hbox {if }\quad k=4 \, \hbox {and } \, \varepsilon = 4; \\ \lfloor \frac{\varepsilon ^2}{2}\rfloor +6, &{} \quad \hbox {if }\quad k=4 \, \hbox {and }\, \varepsilon \ge 5 ; \\ \lceil \frac{(\varepsilon +1)^2}{2}\rceil -(\varepsilon +1)+\frac{(k-1)^2}{4}, &{} \quad \hbox {if }\quad k=4t+1\ (t\ge 1); \\ \lceil \frac{(\varepsilon +1)^2}{2}\rceil -\varepsilon +\frac{(k-1)^2}{4}, &{}\quad \hbox {if }\quad k=4t+3\ (t\ge 1); \\ \lceil \frac{(\varepsilon +1)^2}{2}\rceil -\varepsilon +\frac{(k-1)^2+5}{4}, &{} \quad \hbox {if }\quad k=2t\ (t\ge 3). \end{array} \right. \end{aligned}$$

This completes the proof. \(\square \)

5 Concluding Remarks and Further Research Problems

In this paper, we determine the trees having the greatest Mostar index among the tree set with a given segment sequence and among the tree set with a given size and together with a given segment number, respectively. We also identify the trees having the least Mostar index among the later set.

Quite recently, as a generalization of the Mostar index, the edge-Mostar index [5] was introduced:

$$\begin{aligned} Mo_e(G)= \sum _{e=uv\in E_G}|m_u(e|G)-m_v(e|G)|, \end{aligned}$$

where \(m_u(e|G)=\{e'|{d(}e',u)< {d(}e',v)\}\) and \(m_v(e|G)=\{e'|{d(}e',v)< {d(}e',u)\}\), respectively. The edge Mostar index of some polycyclic aromatic structures [5] and some other chemical graphs [1, 19, 23] have been studied. It is a natural problem to look for extremal graphs among all kinds of graph sets respect to the edge Mostar index, as those have been studied respect to the Mostar index. It seems that as the number of cycles in graphs increases, the extremal graphs are quite different respect to the two distinct indices.

One can also consider the extremal problems respect to the Mostar index, among trees or general graphs given parameters related to all kinds of vertex sequences [16]. For example, consider the graphs with given Grundy domination number which is the maximum length of a dominating sequence [16].