1 Introduction

Let \(G = (V(G), E(G))\) be a graph, \(X\subseteq V(G)\), and \(u,v\in V(G)\). Then, u and v are resolved by X if there exists \(x\in X\) such that \(d_G(u,x) \ne d_G(v,x)\), where \(d_G(y,z)\) denotes the shortest path distance between vertices y and z of G. A set X such that each pair of vertices of G is resolved by X is a resolving set of G. A smallest resolving set is a metric basis of G; its cardinality is the metric dimension of G denoted by \(\dim (G)\). This concept is one of the central ones in the field of metric graph theory, and its popularity stems, among other things, from the fact that it has found many applications in fields as diverse as computer science, chemistry, biology, and social sciences. For a better understanding of the concept and its applications, see the recent survey [18], while for a comprehensive survey on its variants see the other recent survey [11].

In 2010, Okamoto et al. [12] introduced the local metric dimension of a graph as a natural version of the metric dimension. In this version, which was further researched in particular in [1,2,3, 6, 10, 13, 14, 17], we need to resolve only pairs of adjacent vertices. The dual concept, in which all pairs of non-adjacent vertices are to be resolved, has surprisingly not been considered in the literature. In this paper, we fill this gap.

If \(X\subseteq V(G)\) resolves each pair of non-adjacent vertices, then we speak of a nonlocal resolving set. A smallest nonlocal resolving set is a nonlocal metric basis of G, its cardinality is the nonlocal metric dimension of G and will be denoted by \(\text {dim}_{\textrm{n}\ell }(G)\). By definition,

$$\begin{aligned} \textrm{dim}_{\textrm{n}\ell }(G) \le \dim (G) \end{aligned}$$
(1)

holds for every graph G. The difference can be arbitrary large as already demonstrated by complete graphs for which we have \(\text {dim}_{\textrm{n}\ell }(K_n) = 0\) and \(\dim (K_n) = n-1\) for every \(n\ge 1\).

We proceed as follows. In the next section, we first recall definitions, notation, and a result needed later. Then, we characterize the graphs with the nonlocal metric dimension equal to 1 and show that \(\textrm{dim}_{\textrm{n}\ell }(G) = \dim (G)\) holds for bipartite graphs G. In Sect. 3, we determine the nonlocal metric dimension for block graphs and for corona products. The latter result is reduced to a join of a graph with \(K_1\). This motivates us to determine the nonlocal metric dimension of wheels in Sect. 4. In the subsequent section, we prove two upper bounds on the nonlocal metric dimension and characterize graphs G with \(\text {dim}_{\textrm{n}\ell }(G) = n(G) - 2\). In Sect. 6, we embed an arbitrary graph into a supergraph with a small nonlocal metric dimension and small diameter. In the concluding section, directions for further study are indicated.

2 Preliminaries

Unless stated otherwise, graphs considered will be connected. The order of a graph G will be denoted by n(G). If \(X=\{x_1,\dots ,x_k\}\) and \(u\in V(G)\), then the metric representation of u with respect to X is the vector \(r(u|X)=(d_G(u,x_1),\dots , d_G(u,x_k))\). The diameter \(\textrm{diam}(G)\) of G is the largest distance between pairs of vertices of G. The clique number of G is the order of a largest complete subgraph in G and denoted by \(\omega (G)\). As usual, the chromatic number of G is denoted by \(\chi (G)\). The edge cover number \(\beta '(G)\) of G is the smallest number of edges such that each vertex is incident with at least one of these edges. The join \(G+H\) of graphs G and H is obtained from the disjoint union of a copy of G and a copy of H by adding an edge between each vertex of G and each vertex of H. The complement of G will be denoted by \({\overline{G}}\). For a positive integer k, we will use the notation \([k] = \{1,\ldots , k\}\).

A vertex of degree at least 3 in a tree T is called a branch vertex. A leaf u of T is called a terminal leaf of a branch vertex v of T if \(d_T(u,v) < d_T(u,w)\) for every other branch vertex w of T. A branch vertex v of T is an exterior branch vertex of T if it has at least one terminal leaf. The path from an exterior branch vertex to its terminal leaf is called a terminal path. Let \(n_1(T)\) denote the number of leaves of T, and let \(\textrm{ex}(T)\) denote the number of exterior branch vertices of T. In [5, 7, 15], it was proved that if T is a tree that is not a path, then

$$\begin{aligned} \dim (T) = n_1(T) - \textrm{ex}(T). \end{aligned}$$
(2)

We already mentioned that \(\text {dim}_{\textrm{n}\ell }(K_n) = 0\) for \(n\ge 1\). Moreover, as soon as G is not complete, \(\text {dim}_{\textrm{n}\ell }(G)\ge 1\). Clearly, \(\text {dim}_{\textrm{n}\ell }(P_n) = 1\) for \(n\ge 3\). It is also not difficult to see that \(\text {dim}_{\textrm{n}\ell }(C_n) = 2\) for \(n\ge 4\).

To characterize graphs G with \(\text {dim}_{\textrm{n}\ell }(G) = 1\), we need the following concept. If \(x\in V(G)\) and \(k\ge 0\), then \(L_k(x) = \{u\in V(G):\ d_G(x,u) = k\}\) is a distance level of x. In particular, \(L_0(x) = \{x\}\), and \(L_1(x)\) is the (open) neighborhood of x.

Proposition 2.1

If G is a non-complete graph, then \(\text {dim}_{\textrm{n}\ell }(G) = 1\) if and only if there exists a vertex x such that \(L_k(x)\) induces a complete graph for every \(k \le \textrm{diam}(G)\).

Proof

Assume first that \(\text {dim}_{\textrm{n}\ell }(G) = 1\) and let \(\{x\}\) be a nonlocal metric basis. If \(u, v\in L_k(x)\) for some \(k\ge 1\), then \(d_G(x,u) = d_G(x,v) = k\), and hence, u and v must be adjacent. Thus, \(L_k(x)\) induces a complete graph. (\(L_0(x)\) is trivially complete.)

Conversely, let x be a vertex whose all distance levels induce complete graphs. Therefore, if \(u, v\in V(G)\) and \(uv\notin E(G)\), then \(d_G(x,u) \ne d_G(x,v)\) and so u and v are resolved by x. \(\square \)

In general, \(\text {dim}_{\textrm{n}\ell }(G)\) can be arbitrary smaller than \(\dim (G)\). This cannot happen if G is bipartite as the next result asserts.

Proposition 2.2

If G is a bipartite graph with \(n(G)\ge 3\), then \(\text {dim}_{\textrm{n}\ell }(G) = \dim (G)\).

Proof

By (1), we have \(\text {dim}_{\textrm{n}\ell }(G) \le \dim (G)\). Let X be a nonlocal metric basis of G. As \(n(G)\ge 3\), G is not complete and hence \(|X| \ge 1\). Consider arbitrary vertices \(u,v \in V(G)\). If \(uv \notin E(G)\), then u and v are resolved by X because X is a nonlocal resolving set. If \(uv \in E(G)\), then u and v are resolved by X since G is bipartite. It follows that X is also a resolving set. Hence, \(\dim (G) \le |X| = \text {dim}_{\textrm{n}\ell }(G)\) and we are done. \(\square \)

3 Block Graphs and Corona Products

Proposition 2.2 implies that if T is a tree with \(n(T)\ge 3\), then \(\text {dim}_{\textrm{n}\ell }(T) = \dim (T)\). This fact generalizes to block graphs as follows. Let G be a block graph. The block-cutpoint tree \({\widehat{G}}\) of G is the tree whose vertices are the blocks and the cut-vertices of G, and a block B is adjacent to a cut-vertex v if \(v\in V(B)\), cf. [19, Definition 4.1.20].

Theorem 3.1

If G is a block graph with \(n(G)\ge 3\), then \(\text {dim}_{\textrm{n}\ell }(G) = \dim ({\widehat{G}})\).

Proof

We can extend the terminology for trees from the previous section to block graphs as follows. Let G be a block graph. A block B of G is called a branch block if the vertices of B have at least three independent neighbors outside of B. A branch block B of G is an exterior branch block of G if in \({\widehat{G}}\) there exist \(t\ge 1\) terminal paths emanating from a cut-vertex of B. If so, we say that B has t rays.

Let now X be a nonlocal resolving set of G. If B is an exterior branch block of G with t rays, then we claim that X has at least \(t-1\) vertices in these rays, each one from a different ray. Indeed, otherwise there exist two rays \(R_1\) and \(R_2\) with no vertex from X. Let \(R_1\) and \(R_2\) be attached to B at vertices \(u_1\) and \(u_2\) (note that \(u_1 = u_2\) is possible), and select neighbors \(v_1\) and \(v_2\) of \(u_1\) and \(u_2\) in \(R_1\) and \(R_2\), respectively. Then, \(v_1\) and \(v_2\) are not adjacent and have the same metric representation with respect to X. This proves the claim. Each exterior branch block of G corresponds to an exterior branch vertex of \({\widehat{G}}\). Since \({\widehat{G}}\) is a tree, (2) implies that \(\text {dim}_{\textrm{n}\ell }(G) \ge \dim ({\widehat{G}})\).

To prove that \(\text {dim}_{\textrm{n}\ell }(G) \le \dim ({\widehat{G}})\) holds, let X be a metric basis of \({\widehat{G}}\). We may without loss of generality assume that every element of X is a leaf of \({\widehat{G}}\). Then, each element \(x\in X\) corresponds to a terminal block \(B_x\) of G, that is, a block which contains exactly one cut-vertex. For every \(x\in X\), let \(w_x\) be an arbitrary but fixed vertex of \(B_x\) which is not a cut-vertex. Set \(Y = \{w_x:\ x\in X\}\). Since we do not need to resolve adjacent vertices, it is straightforward to check that Y is a nonlocal resolving set of G. Hence, \(\text {dim}_{\textrm{n}\ell }(G) \le |Y| = |X| = \dim ({\widehat{G}})\). \(\square \)

The metric dimension of block graphs was studied in [8]. It was proved that the metric dimension of a block graph G is equal to the metric dimension of a tree, obtained from G by replacing each block B of size at least 3 by a star whose leaves are the vertices of B. The local metric dimension of block graphs was investigated in [14].

Let G and H be graphs where \(V(G) = \{g_1, \ldots ,g_{n(G)}\}\). The corona product of G and H, denoted by \(G\odot H\), is a graph obtained from the disjoint union of a copy of G and n(G) copies of H, denoted by \(H_i\), \(i\in [n(G)]\). The product \(G\odot H\) is then constructed by making \(g_i\) adjacent to every vertex in \(H_i\) for each \(i\in [n(G)]\). Let further \(\widetilde{H_i}\) be the subgraph of \(G\odot H\) induced by \(V(H_i)\cup \{g_i\}\). Clearly, \(\widetilde{H_i}\cong H + K_1\). We will use this notation in the rest of the section.

The metric dimension of corona products has been investigated in [9, 20]. The local metric dimension of corona products has been studied in [13] and more generally of generalized hierarchical products in [10]. In particular, in [13] it is proved for the local metric dimension \(\textrm{dim}_{\ell }\) that if G is a connected graph and H is a graph of radius at least 4, then \(\textrm{dim}_{\ell }(G\odot H)=n(G)\cdot \textrm{dim}_{\ell }(H+K_1)\). In general, \(\textrm{dim}_{\ell }(G\odot H)\le n(G)\cdot \textrm{dim}_{\ell }(H+K_1)\), see [10]. Here we add the following formula for the nonlocal metric dimension.

Theorem 3.2

If G is a graph and H a non-complete graph, then

$$\begin{aligned} \textrm{dim}_{\textrm{n}\ell }(G\odot H) = n(G)\cdot \textrm{dim}_{\textrm{n}\ell }(H + K_1). \end{aligned}$$

Proof

Let X be a nonlocal metric basis of \(G\odot H\) and let \(X_i = X \cap V(\widetilde{H_i})\). If \(u,v\in V(H_i)\) and \(w\in V(G\odot H)\setminus V(H_i)\), then \(d_{G\odot H}(u,w) = d_{G\odot H}(v,w)\). Since also \(d_{G\odot H}(u,g_i) = d_{G\odot H}(v,g_i) = 1\), any two non-adjacent vertices from \(H_i\) must be resolved by some vertex from \(H_i\). Therefore, \(X_i\) is a nonlocal resolving set of \(\widetilde{H_i}\) and so \(|X_i| \ge \text {dim}_{\textrm{n}\ell }(\widetilde{H_i}) = \text {dim}_{\textrm{n}\ell }(H + K_1)\). Consequently,

$$\begin{aligned} \text {dim}_{\textrm{n}\ell }(G\odot H) = |X| = \sum _{i=1}^{n(G)} |X_i| \ge \sum _{i=1}^{n(G)} \text {dim}_{\textrm{n}\ell }(\widetilde{H_i}) = n(G)\cdot \text {dim}_{\textrm{n}\ell }(H + K_1). \end{aligned}$$

Let now Y be a nonlocal metric basis of \(H\odot K_1\). Since H is not complete, \(|Y|\ge 1\). For each \(i\in [n(G)]\), let \(Y_i\) be the copy of Y in \(\widetilde{H_i}\). Note that \(g_i\notin Y_i\). We claim that \(\cup _{i=1}^{n(G)}Y_i\) is a nonlocal resolving set of \(G\odot H\). Indeed, if vertices u and v from \(V(H_i)\) are non-adjacent, then they are resolved by some vertex from \(Y_i\). Assume next \(u\in V(\widetilde{H_i})\) and \(v\in V(\widetilde{H_j})\), where \(i\ne j\). If \(y_i \in Y_i\), then \(d(y_i,u) \le 2\) and \(d(y_i,v) \ge 3\), hence u and v are again resolved. We have thus seen that \(\cup _{i=1}^{n(G)}Y_i\) is a nonlocal resolving set, and henceforth,

$$\begin{aligned} \textrm{dim}_{\textrm{n}\ell }(G\odot H) \le |\cup _{i=1}^{n(G)}Y_i| = n(G)\cdot |Y| = n(G)\cdot \textrm{dim}_{\textrm{n}\ell }(H + K_1). \end{aligned}$$

We conclude that \(\text {dim}_{\textrm{n}\ell }(G\odot H) = n(G)\cdot \text {dim}_{\textrm{n}\ell }(H + K_1)\). \(\square \)

In the case when the second factor of a corona product is complete, we can bound the nonlocal metric dimension as follows.

Theorem 3.3

If G is a graph and \(n\ge 1\), then

$$\begin{aligned} \dim (G) \le \textrm{dim}_{\textrm{n}\ell }(G\odot K_n) \le n(G). \end{aligned}$$

Proof

To prove the upper bound, we claim that V(G) is a nonlocal resolving set of \(G\odot K_n\). Indeed, let \(u, v \in V(G\odot K_n)\setminus V(G)\) be two non-adjacent vertices. Then, \(u\in H_i\) and \(v\in H_j\) for some i and j, where \(i\ne j\). As \(d_{G\odot K_n}(u,g_i) = 1\) and \(d_{G\odot K_n}(v,g_i)\ge 2\), the claim follows. Hence, \(\text {dim}_{\textrm{n}\ell }(G\odot K_n) \le n(G)\).

Let now X be a nonlocal metric basis of \(G\odot H\); then \(|X| = \textrm{dim}_{\textrm{n}\ell }(G\odot H)\). Let \(Y\subseteq V(G)\) be the set obtained from X by replacing each vertex \(u\in X\cap V(\widetilde{H_i})\) by \(g_i\). Note that this in particular means that if \(g_i\in X\), then also \(g_i\in Y\). Clearly, \(|Y| \le |X|\). We claim that Y is a resolving set of G. For this sake, consider arbitrary vertices \(g_i, g_j\in V(G)\subseteq V(G\odot H)\). Let \(u\in V(H_i)\) and \(v\in V(H_j)\). Since X is a nonlocal metric basis of \(G\odot H\) and \(uv\notin E(G\odot H)\), there exists a vertex \(w\in X\) such that \(d_{G\odot H}(u,w) \ne d_{G\odot H}(v,w)\). If \(w\in \widetilde{H_i} \cup \widetilde{H_j}\), then \(g_i\in Y\) or \(g_j\in Y\) and there is nothing to be proved. Suppose henceforth that \(w\in \widetilde{H_k}\), where \(k\ne i,j\). If \(w\ne g_k\), then

$$\begin{aligned} 1 + d_G(g_i, g_k) + 1 = d_{G\odot H}(u,w) \ne d_{G\odot H}(v,w) = 1 + d_G(g_j, g_k) +1, \end{aligned}$$

and if \(w = g_k\), then

$$\begin{aligned} 1 + d_G(g_i, g_k)&= 1 + d_G(g_i, w) \\&= d_{G\odot H}(u,w) \ne d_{G\odot H}(v,w) \\&= 1 + d_G(g_j, w) = 1 + d_G(g_j, g_k). \end{aligned}$$

In either case, we get \(d_G(g_i, g_k) \ne d_G(g_j, g_k)\). As \(g_k\in Y\), we have proved that Y is a resolving set of G which in turn implies that

$$\begin{aligned} \dim (G) \le |Y| \le |X| =\text {dim}_{\textrm{n}\ell }(G\odot H) \end{aligned}$$

and we are done. \(\square \)

If \(r,s\ge 3\), then it can be checked that \(\text {dim}_{\textrm{n}\ell }(K_{r,s}\odot K_n) = r + s - 2 = \text {dim}_{\textrm{n}\ell }(K_{r,s}) = \dim (K_{r,s})\). This shows the sharpness of the lower bound of Theorem 3.3. On the other hand, if \(m\ge 2\) and \(n\ge 1\), then \(\text {dim}_{\textrm{n}\ell }(P_m\odot K_n) = 2\). Since \(\dim (P_m) = 1\) and \(n(K_m) =m\), the case \(m=2\) shows the tightness of the upper bound, while the cases \(m\ge 3\) demonstrate that the intermediate values are also attainable.

4 Nonlocal Metric Dimension of Wheels

In Theorem 3.2, the nonlocal metric dimension of a corona product \(G\odot H\) is reduced to the nonlocal metric dimension of the join of H with \(K_1\). To determine the latter deserves a special attention. Here we solve it for the join of a cycle with \(K_1\), that is, for wheels. Recall that the wheel graph \(K_1+C_{n}\) of order \(n+1\ge 4\) is denoted by \(W_{1,n}\).

As a consequence of [13, Corollary 5(iv)], we obtain \(\textrm{dim}_{\ell }(W_{1,n}) = \lceil n/4\rceil \). The metric dimension of \(W_{1,n}\) was independently studied in [4, 16], where it is proved that if \(n\ge 7\), then

$$\begin{aligned} \dim (W_{1,n}) = \left\lfloor {\frac{2n+2}{5}}\right\rfloor . \end{aligned}$$

Clearly, \(\text {dim}_{\textrm{n}\ell }(W_{1,3})=1\) and \(\text {dim}_{\textrm{n}\ell }(W_{1,4})=\text {dim}_{\textrm{n}\ell }(W_{1,5})=\text {dim}_{\textrm{n}\ell }(W_{1,6})=2\). The main result of this section reads as follows.

Theorem 4.1

If \(n\ge 7\), then

$$\begin{aligned} \textrm{dim}_{\textrm{n}\ell }(W_{1,n})=\left\lfloor {\frac{2n}{5}}\right\rfloor . \end{aligned}$$

Note that if \(n\ge 7\), then \(\dim (W_{1,n}) = \textrm{dim}_{\textrm{n}\ell }(W_{1,n})\) if and only if \(n \bmod 5 \in \{0, 1, 3\}\). Otherwise, \(\textrm{dim}_{\textrm{n}\ell }(W_{1,n}) = \dim (W_{1,n}) - 1\). In the rest of the section, we prove Theorem 4.1, for which some additional terminology is needed.

Let \(V(C_n)=\{0,1,\dots ,n-1\}\) with natural adjacency. Operation with vertices will be done modulo n. Let v be the central vertex of the wheel \(W_{1,n}\), where \(n\ge 7\). Notice first that v does not belong to any nonlocal metric basis, since for any \(0\le i\le n-1\), v and i are adjacent. Let \(X\subset V(C_n)\) be a set of vertices such that \(|X|\ge 2\). A gap of X is a set of vertices \(A_{i,j}=\{i+1,\dots ,j-1\}\), \(|i-j|\ge 1\), of \(C_n\) such that \(i,j\in X\) and \(\{i+1,\dots ,j-1\}\cap X=\emptyset \). We call i and j neighboring vertices of X. Two gaps \(A_{i,j}\) and \(A_{j,k}\) are called neighboring gaps.

Lemma 4.2

Let \(n\ge 7\), and let S be a nonlocal metric basis of \(W_{1,n}\). Then, the following hold.

  1. (i)

    \(|A_{i,j}| \le 4\) for each gap of S.

  2. (ii)

    \(|A_{i,j}| \ge 3\) holds for at most one gap of S.

  3. (iii)

    If \(|A_{i,j}|\ge 2\), then each of the two neighboring gaps of \(A_{i,j}\) contains at most one vertex.

  4. (iv)

    Moreover, \(W_{1,n}\) contains a nonlocal metric basis \(S'\) that fulfils conditions (i)-(iii) and in addition has no gap of size 3.

Proof

(i) Consider the gap \(A_{i,j}\) and suppose that \(j\ge i+6\), where \(i\le n-1\). Then, the vertices \(i+2\) and \(i+4\) have the same metric representation with respect to S. As they are not adjacent, we have a contradiction.

(ii) Suppose there exist two distinct gaps \(A_{i,i+k}\) and \(A_{j,j+k'}\), where \(k, k'\in \{4, 5\}\). Then, for two non-adjacent vertices \(i+2\) and \(j+2\) we have \(r(i+2|S)=r(j+2|S)\), a contradiction.

(iii) Let \(A_{i,j}\) be a gap with \(j\ge i+3\). Consider now a neighboring gap, without loss of generality let it be \(A_{i',i}\), and suppose that \(i - i' > 2\). Then, the vertices \(i-1\) and \(i+1\) have the same metric representation with respect to S. Again, as they are not adjacent, we have a contraction.

(iv) Assume that S contains a gap \(A_{i,i+4}\). By (ii), this gap is the only gap of size 3. Moreover, by (iii), there are the following cases to be considered. Assume first that \(i+5\notin S\). Then \(i+6\) must belong to S. Let \(S' = (S \cup \{i+5\})\setminus \{i+4\}\). Having in mind that \(i+2\) and \(i+3\) are adjacent, it is straightforward to verify that \(S'\) is a required nonlocal metric basis. The case when \(i-1\notin S\) is treated analogously. The last case to consider is when \(i-1, i+5\in S\). Then, \(i+6\notin S\) and the set \(S' = (S \cup \{i+6\})\setminus \{i+4\}\) is a required nonlocal metric basis. \(\square \)

Lemma 4.3

Let \(n\ge 7\). If \(X\subseteq V(C_n)\) satisfies conditions (i)–(iii) of Lemma 4.2, then X is a nonlocal resolving set of \(W_{1,n}\).

Proof

Notice that by Proposition 2.1, \(\text {dim}_{\textrm{n}\ell }(W_{1,n})\ge 2\), for \(n\ge 7\). Let \(u\in V(W_{1,n})\setminus X\). As the central vertex v is adjacent to any other vertex, we may assume that \(u\ne v\). We then distinguish three cases.

Case 1: u belongs to a gap \(A_{i,i+2}\) (gap of size 1).

Then, \(u=i+1\) and u has distance 1 to \(i,i+2\in X\) and distance 2 to all other vertices of X. Hence, any other vertex has different metric representation with respect to X because \(n\ge 7\).

Case 2: u belongs to a gap \(A_{i,i+3}\) (gap of size 2).

Let without loss of generality \(u=i+1\). Then u has distance 1 to i and distance 2 to all other vertices of X. By condition (iii) from Lemma 4.2, there is no any other vertex with the same metric representation.

Case 3: u belongs to a gap \(A_{i,i+j}\), \(j\in \{4,5\}\).

If \(u=i+1\), then u has distance 1 to i and distance 2 to all the other vertices of X. Hence, by condition (iii) of Lemma 4.2, there is no other vertex with the same metric representation. The case when \(u=i+j-1\) is done similarly. Now, if \(u\in \{i+2,i+j-2\}\), then \(r(u|X)=(2,\dots ,2)\). If \(j=4\), then there is only one such vertex, and if \(j=5\), there are two such vertices. In the latter case, these two vertices are adjacent. By condition (ii) from Lemma 4.2, no other vertex has this metric representation. \(\square \)

We are now in a position to prove Theorem 4.1. We construct a set \(S\subseteq V(W_{1,n})\) with \(|S|=\left\lfloor {\frac{2n}{5}}\right\rfloor \) depending on the residue class modulo 5.

Case 1: \(n \bmod \, 5\in \{0,1\}\).

Then, \(n=5k\) or \(n=5k+1\), where \(k\ge 2\). In both cases, let \(S=\{5i,5i+2: i\in [k-1]\}\cup \{0,5k-1\}\). Notice that \(|S|=2k=\left\lfloor {\frac{2n}{5}}\right\rfloor \).

Case 2: \(n \equiv 2 \bmod 5\).

Then, \(n=5k+2\), where \(k\ge 1\). Let \(S=\{5i,5i+2: 1\le i\le k-1\}\cup \{0,5k\}\). Then \(|S|=2k=\left\lfloor {\frac{2n}{5}}\right\rfloor \).

Case 3: \(n \bmod \, 5 \in \{3,4\}\).

Then, \(n=5k+3\) or \(n=5k+4\), where \(k\ge 1\). In both cases, let \(S=\{5i,5i+2: i\in [k]\}\cup \{0\}\). Then, \(|S|=2k+1=\left\lfloor {\frac{2n}{5}}\right\rfloor \).

In each case, the set S fulfils the conditions of Lemma 4.3; hence, S is a nonlocal resolving set of \(W_{1,n}\) and thus \(\text {dim}_{\textrm{n}\ell }(W_{1,n})\le \left\lfloor {\frac{2n}{5}}\right\rfloor \).

To prove that \(\text {dim}_{\textrm{n}\ell }(W_{1,n}) \ge \left\lfloor {\frac{2n}{5}}\right\rfloor \), consider an arbitrary nonlocal resolving set X of \(W_{1,n}\). In view of Lemma 4.2(iv), we may without loss of generality assume that X has no gaps of size 3. We distinguish two cases.

Case 1: \(|X|=2r\), where \(r\ge 1\).

By Lemma 4.2(iii), at most r gaps contain two or four vertices, and by Lemma 4.2(ii), at most one of these gaps contains 4 vertices. Hence, there is at most \(2(r-1) + 4 + r = 3r+2\) vertices belonging to the gaps. Since \(n\le 2r+(3r+2)\), we have that \(|X|=2r \ge 2\left( \frac{n-2}{5}\right) \). Since 2r is an integer, we conclude that \(|X| \ge \left\lceil {\frac{2}{5}n-\frac{4}{5}}\right\rceil = \left\lfloor {\frac{2n}{5}}\right\rfloor \).

Case 2: \(|X|=2r+1\), where \(r\ge 1\).

Again, by Lemma 4.2(iii), at most r gaps contain two or four vertices, and by Lemma 4.2(ii), at most one of these gaps contains 4 vertices. Hence, in this case there is at most \(2(r-1) + 4 + (r+1) = 3r+3\) vertices belonging to the gaps. Since \(n\le 2r+1+(3r+3)\), we have that \(|X|=2r+1\ge \left\lceil {\frac{2}{5}n-\frac{3}{5}}\right\rceil \ge \left\lfloor {\frac{2n}{5}}\right\rfloor \).

This proves Theorem 4.1.

5 Upper Bounds

In this section, we prove two upper bounds on the nonlocal metric dimension. Along the way, we show that complete bipartite graphs can be characterized as the graphs G with \(\text {dim}_{\textrm{n}\ell }(G) = n(G) - 2\)

Proposition 5.1

If G is a graph, then \(\textrm{dim}_{\textrm{n}\ell }(G) \le n(G) - \omega (G)\). In particular, if \(n(G)\ge 2\), then \(\textrm{dim}_{\textrm{n}\ell }(G) \le n(G) - 2\).

Proof

Since \(\textrm{dim}_{\textrm{n}\ell }(K_n) = 0\) for \(n\ge 1\), the result holds for complete graphs. Hence, assume in the rest that G is not complete and \(n(G) \ge 3\).

Let Q be a clique of G of order \(\omega (G)\). Then, we claim that \(V(G) \setminus V(Q)\) is a nonlocal resolving set. Indeed, let u and v be non-adjacent vertices. At least one of them is not in Q, say u. Then, \(d_G(u,u) = 0 < d_G(u,v)\), and since \(u\in V(G) \setminus V(Q)\), the claim is proved. Hence, \(\text {dim}_{\textrm{n}\ell }(G) \le n(G) - n(Q) = n(G) - \omega (G)\). The second assertion, \(\text {dim}_{\textrm{n}\ell }(G) \le n(G) - 2\), follows using the same argument except that we consider an arbitrary \(K_2\) as a complete subgraph. \(\square \)

In view of Proposition 5.1, we next describe graphs that attain the bound \(n(G) - 2\).

Proposition 5.2

If G is a graph, then \(\textrm{dim}_{\textrm{n}\ell }(G) = n(G) - 2\) if and only if \(G = K_{s,t}\), where \(s\ge 1\) and \(t\ge 2\).

Proof

If \(\text {dim}_{\textrm{n}\ell }(G) = n(G) - 2\), then by (1) we have \(\dim (G)\ge n(G)-2\). Since the only graphs G with \(\dim (G) = n(G)-1\) are complete graphs, we can restrict our attention to the graphs G with \(\dim (G) = n(G)-2\). In [5], it is proved that \(\dim (G) = n(G) - 2\) if and only if G is one of the following graphs: \(K_{s,t}\) (\(s\ge 1, t\ge 2\)), \(K_s+ \overline{K_t}\) (\(s\ge 1, t\ge 2\)), and \(K_s+ (K_1\cup K_t)\) (\(s\ge 1, t\ge 1\)). By (1) we know that in each of these cases we have \(\text {dim}_{\textrm{n}\ell }(G) \le n(G) - 2\). Hence, we need to determine in which of these cases we have \(\text {dim}_{\textrm{n}\ell }(G) \ge n(G) - 2\).

Consider first complete bipartite graphs \(K_{s,t}\) and let S and T be its bipartition sets, where \(|S| = s\) and \(|T| = t\). If \(u,v\in S\), then u and v have the same distance to all the other vertices. If follows that for each nonlocal metric basis X we have \(|X\cap S| = s-1\). Analogously we get \(|X\cap T| = t-1\). Hence \(|X| = (s-1) + (t-1) = n(K_{s,t}) - 2\).

Consider next joins \(K_s+ \overline{K_t}\), \(s\ge 1\), \(t\ge 2\). The case \(s=1\) has already been treated in the above paragraph, so assume that \(s, t\ge 2\). Then, \(\omega (K_s+ \overline{K_t}) = s + 1 \ge 3\), and hence, by Proposition 5.1 we have \(\textrm{dim}_{\textrm{n}\ell }(K_s+ \overline{K_t}) \le n(K_s+ \overline{K_t}) - \omega (K_s+ \overline{K_t}) < n(K_s+ \overline{K_t}) - 2\).

The last class of graphs to be considered is \(K_s+ (K_1\cup K_t)\), \(s\ge 1\), \(t\ge 1\). If \(s=t=1\), then \(G=P_3\) which has already been considered earlier. And if \(s\ge 2\) or \(t\ge 2\), then \(\omega (G)\ge 3\), and we conclude as in the previous case that none of the graphs qualifies for the theorem. \(\square \)

Theorem 5.3

If G is a graph of girth at least 7, then \(\textrm{dim}_{\textrm{n}\ell }(G) \le \beta '(G) - 1\). Moreover, if G is a tree, then the equality holds if and only if G is obtained from a star by subdividing all but one of the edges at most once.

Proof

Note first that the assertion is true for \(K_2\) since \(\text {dim}_{\textrm{n}\ell }(K_2) = 0\). It is also clear that the result holds for paths since \(\text {dim}_{\textrm{n}\ell }(P_n) = 1\) for \(n\ge 3\). Hence, in the rest \(n(G)\ge 4\) and \(\Delta (G)\ge 3\).

Assume first that there exists an edge cover S of G with \(|S| = \beta '(G)\ge 2\), such that S contains edges xy and \(xy'\), where \(y\ne y'\). We distinguish two cases.

Case 1: \(\deg _G(y) = \deg _G(y') = 1\).

Then, \(\deg _G(x) \ge 3\). We define a set \(X\subset V(G)\) as follows. Put into X all the neighbors of x but \(y'\). Complete the construction of X by putting into it an arbitrary vertex from each of the edges \(f\in S\) which has no vertex yet in X. Let \(x'\) be a neighbor of x different from y and \(y'\). Since G is triangle-free, the vertices \(x'\) are covered either by the edge \(xx'\), or by an edge \(x'x''\), where \(x''\) is not adjacent to x. Therefore, \(|X| \le \beta '(G) - 1\). Note also that \(x\notin X\). We claim that X is a nonlocal resolving set. For this sake, select arbitrary vertices \(u,v\notin X\) such that \(uv\notin E(G)\). If \(u\in \{x, y'\}\), then because \(\deg _G(y) = 1\), the vertices u and v are resolved by y. Assume next that \(u, v\notin \{x, y'\}\). Then, there exist vertices \(u'\) and \(v'\) such that \(uu', vv'\in E(G)\) and \(u',v'\in X\). We claim that u and v are resolved by \(u'\) and \(v'\). If this is not the case, then since \(d_G(u,u') = 1\), we have \(d_G(v,u') = 1\), and because \(d_G(v,v') = 1\), we have \(d_G(u,v') = 1\). But this implies that \(uu'vv'u\) is a 4-cycle, a contradiction with our girth assumption.

Case 2: \(\deg _G(y) \ge 2\).

Let \(y''\) be a neighbor of y different from x. Then, we infer that \(yy''\notin S\). Indeed, if \(yy''\in S\), then \(S' = S \setminus \{xy\}\) is an edge cover of G of cardinality \(\beta '(G) - 1\). Hence, \(y''\) is an end-vertex of some edge \(y''y'''\in S\). Define now a set \(X\subset V(G)\) as follows. First put x and \(y''\) into X. In addition, for any edge \(f\in S\setminus \{xy, xy', y''y'''\}\) put into X an arbitrary vertex from f. Note that \(|X| \le \beta '(G) - 1\). We claim that X is a nonlocal resolving set. Let \(u,v\notin X\) such that \(uv\notin E(G)\). Then, we see that in every case there exist vertices \(u'\) and \(v'\) such that \(uu', vv'\in E(G)\) and \(u',v'\in X\). In particular, if \(u=y\) and \(v=y'\), then set \(u'=y''\) and \(v'=x\). Similarly, if \(u=y\) and \(v=y'''\), then select \(u' = x\) and \(v' = y''\). And if \(u=y'\) and \(v=y'''\), then set \(u' = x\) and \(v' = y''\). In any case we see that the vertices u, v, \(u'\) and \(v'\) lead to a 4-cycle.

Assume second that every edge cover G has cardinality n(G)/2. Let S be such an edge cover. Again we distinguish two cases.

Case 1: every edge from S has an end-vertex of degree 1.

Let \(S = \{x_iy_i:\ i\in [n(G)/2]\}\) and assume without loss of generality that \(\deg (x_i) = 1\) for all \(i\in [n(G)/2]\). Set \(X = \{x_2, \ldots , x_{n(G)/2}\}\). We claim that X is a nonlocal resolving set. Let u and v be arbitrary non-adjacent vertices from \(V(G)\setminus X\). Then, at least one of u or v is from \(\{y_2, \ldots , y_{n(G)/2}\}\), say \(u=y_i\), \(i\ge 2\). But then \(x_i\) resolves u and v, and the claim is proved.

Case 2: there is an edge \(xy\in S\) such that \(\deg _G(x)\ge 2\) and \(\deg _G(y)\ge 2\).

Let \(x'\) be a neighbor of x different from y, and let \(y'\) be a neighbor of y different from x. By the assumption on S, there exist vertices \(x''\) and \(y''\) such that \(x'x'', y'y''\in S\). Let \(X\subset V(G)\) be the set containing \(x'\), \(y'\), and an arbitrary vertex from each edge \(f\in S' = S\setminus \{xy, x'x'', y'y''\}\). We claim that X is a nonlocal resolving set. Let \(f=ww'\in S'\), where \(w'\in X\). Then, since \(d_G(w,w') = 1\) and since each of the vertices x, y, \(x''\), and \(y''\) has either \(x'\in X\) or \(y'\in X\) as a neighbor, we get that X resolves w from each of the vertices from \(\{x,y,x'',y''\}\). Similarly we infer that the pairs \(x'',y\), and \(x'',y''\), and \(x,y''\) are resolved by X. The only pairs left to be considered are \(x,x''\) and \(y,y''\). Suppose on the contrary that the pair \(x,x''\) is not resolved by X. Since \(d_G(x,y') = 2\), we must have \(d_G(x'',y') = 2\). Then \(y'x'\in E(G)\), or \(y''x''\in E(G)\), or there is a new vertex z such that \(y'z, zx''\in E(G)\). In either case, we have a cycle of length at most 6 in G which is not possible. The other pair \(y,y''\) is treated analogously.

Let now G be a tree. Let W be the set of exterior branch vertices of T, and for a vertex \(w\in W\), let p(w) be the number of terminal paths of w. Then, we have

$$\begin{aligned} \beta '(T) \ge \sum _{w\in W} p(w). \end{aligned}$$

On the other hand, by (2) and Proposition 2.2 we have

$$\begin{aligned} \begin{aligned} \text {dim}_{\textrm{n}\ell }(T) = \sum _{w\in W} (p(w)-1). \end{aligned} \end{aligned}$$

Hence, \(\text {dim}_{\textrm{n}\ell }(G) = \beta '(G) - 1\) can hold only when \(|W| = 1\). Suppose hence that G is a tree with only one exterior branch vertex. Then, G is obtained from a star \(K_{1,n}\), \(n\ge 3\), by subdividing each of its edges an arbitrary number of times. By (2), \(\text {dim}_{\textrm{n}\ell }(G) = n-1\). Moreover, if at least one edge of \(K_{1,n}\) has been subdivided at least two times, then \(\beta '(G) \ge n+1\). Suppose next that each edge of \(K_{1,n}\) has been subdivided exactly once. Then, \(\beta '(G) = n+1\). So we are left with trees G obtained from \(K_{1,n}\) by subdividing all but one of the edges at most once. In this case, we have \(\text {dim}_{\textrm{n}\ell }(G) = n-1 = \beta '(G) - 1\). \(\square \)

6 Embeddings

In our final result, we prove that any graph can be embedded as an induced subgraph into a supergraph with a small nonlocal metric dimension and small diameter. More precisely, the following holds.

Theorem 6.1

Every connected graph G is an induced subgraph of a graph H with \(\textrm{dim}_{\textrm{n}\ell }(H) \le \left\lceil \log (\chi ({\overline{G}}))\right\rceil \) and \(\textrm{diam}(H) \le 4\). Moreover, if \(2^{k-1} \le \chi ({\overline{G}})< 2^k\), for some integer k, then \(\textrm{diam}(H) \le 3\).

Proof

If \(\chi ({\overline{G}}) = 1\), then \({\overline{G}}\) is an edge-less graph and hence G is complete. Then, by definition, \(\text {dim}_{\textrm{n}\ell } (G) = 0\), and hence, the conclusion holds in this case by embedding the complete graph into itself. We may thus assume in the rest that \(\chi ({\overline{G}}) = s \ge 2\). Let k be the unique integer with \(2^{k-1} < s \le 2^{k}\).

Let \(X_0, \ldots , X_{s-1}\) be the color classes of \({\overline{G}}\) under some optimal coloring of it. By our assumption, \(2^{k-1} < s \le 2^{k}\). Then, the sets \(X_0, \ldots , X_{s-1}\), respectively, induce complete subgraphs of G. Since G is connected, we may without loss of generality assume that there exists an edge connecting a vertex from \(X_0\) by a vertex from \(X_{s-1}\). Construct now a graph H as follows. First take the disjoint union of G and \(K_k\). For each \(X_i\) write i in its binary representation, say \(i = i_1\ldots i_k\). Then, for each j such that \(i_j = 0\), add all the edges between the vertex \(j\in V(K_k)\) and \(X_i\). See Fig. 1 for an example of the construction where G is the Petersen graph P. For it, note that \(\chi ({\overline{P}}) = 5\).

Fig. 1
figure 1

Embedding the Petersen graph into a graph H as in the proof of Theorem 6.1. A thick edge means that a bottom vertex is adjacent to both encircled vertices

We claim that \(D = V(K_k)\) is a nonlocal resolving set of H. For this sake, let u and v be arbitrary non-adjacent vertices of H. If at least one of u and v belongs to D, there is nothing to prove. Otherwise, \(u \in X_i\) and \(v\in X_j\), where \(i\ne j\). If \(i = i_1\ldots i_k\) and \(j = j_1\ldots j_k\) are the binary representations of i and j, then there exists p such that, without loss of generality, \(i_p = 0\) and \(j_p = 1\). Then, \(d_{H}(p,u) = 1 \ne 2 = d_{H}(p,v)\); hence, u and v are resolved. This proves the claim. Since \(|D| = k = \left\lceil \log (s)\right\rceil = \left\lceil \log (\chi ({\overline{G}}))\right\rceil \), we conclude that \(\text {dim}_{\textrm{n}\ell }(H) \le \left\lceil \log (\chi ({\overline{G}}))\right\rceil \).

To show that \(\textrm{diam}(H) \le 4\), let again u and v be arbitrary vertices of H. Note first that if \(u\in V(K_k)\), then \(d_{H}(u,v)\le 2\). Assume, hence, that \(u\in X_i\) and \(v\in X_j\), where \(i < j\). Suppose first \(j < 2^k\). Then, each of u and v has a neighbor in \(V(K_k)\) which implies that \(d_{H}(u,v)\le 3\). Note that this fact in particular implies that if \(\chi ({\overline{G}}) < 2^{k}\), then \(\textrm{diam}(H) \le 3\). Suppose second that \(j = 2^k\). By our selection of \(X_0\) and \(X_{2^k}\), there is an edge \(v'w\), where \(v'\in X_{2^k}\) and \(w\in X_0\). As w is adjacent to all the vertices of \(V(K_k)\) and u has at least one neighbor in \(V(K_k)\), we have a uv-path of length 4. \(\square \)

A result for the standard metric dimension which would be parallel to Theorem 6.1 is not possible. The reason is the following. Imagine a connected, non-complete graph G and having a color class (in an optimal coloring of it) of order \(2^r\), \(r\ge 2\). Then, G contains a clique of the same order and hence in whichever graph H we embed G as an induced subgraph, we have \(\omega (H)\ge 2^r\). Then, [5, Theorem 1] which asserts that if G is a graph with \(\textrm{diam}(G) = d\), then \(f(n,d) \le \dim (G) \le n - d\), where f(nd) is the least positive integer k for which \(k + d^k \ge n\), implies that \(\dim (H)\ge r\). So \(\dim (H)\) can be arbitrary larger than \(\left\lceil \log (\chi ({\overline{G}}))\right\rceil \) (actually, arbitrary larger than \(\chi ({\overline{G}})\) for that matter).

7 Concluding Remarks

In this article, we have introduced the concept of nonlocal metric dimension, which seems to deserve wider interest, not least because it is in some sense a complementary concept to the established local metric dimension. Many problems about this new concept remain open, let us mention here just a few that follow from our results.

In Theorem 3.2, we have proved a formula for the local metric dimension of corona products with the second factor being not complete. Extending this theorem (as done in [10] for the local metric dimension) to generalized hierarchical products is open. In view of Theorem 3.3, it would be interesting to prove a formula for \(\text {dim}_{\textrm{n}\ell }(G\odot K_n)\). Theorem 5.3 is proved for graphs of girth at least 7. We suspect that the condition can be relaxed to girth at least 5. Moreover, the edge cover number in triangle-free graphs (that is, of girth at least 4) is equal to the clique cover number. Hence extending Theorem 5.3 to arbitrary graphs, where the upper bound would be stated as a function of the clique covering number would be of interest.