On the complexity of distributed BFS in ad hoc networks with spontaneous wake-up.

We study time and message complexity of the problem of building a BFS tree by a spontaneously awaken node in ad hoc network. Computation is in synchronous rounds, and messages are sent via point-to-point bi-directional links. Network topology is modeled by a graph. Each node knows only its own id and the id’s of its neighbors in the network and no pre-processing is allowed; therefore the solutions to the problem of spanning a BFS tree in this setting must be distributed. We deliver a deterministic distributed solution that trades time for messages, mainly, with time complexity O ( D · min( D, n/f ( n )) · log D · log n ) and with the number of point-to-point messages sent O ( n · (min( D, n/f ( n ))+ f ( n )) · log D · log n ) , for any n -node network with diameter D and for any monotonically non-decreasing sub-linear integer function f . Function f in the above formulas come from the threshold value on node degrees used by our algorithms, in the sense that nodes with degree at most f ( n ) are treated differently that the other nodes. This yields the ﬁrst BFS-ﬁnding deterministic distributed algorithm in ad hoc networks working in time o ( n ) and with o ( n 2 ) message complexity, for some suitable functions f ( n ) = o ( n/ log 2 n ) , provided D = o ( n/ log 4 n ) . was also studied in various models and scenarios, see for example Chlebus and Kowalski (2006) for results and references regarding all-to-all communication in fully-connected message passing system with dynamic crashes, Bienkowski et al. (2010) for recovering from crashes in networks of general topology, and Hedet-niemi et al. (1988); Hromkovic et al. (2005); Pelc (1996) for a number of fault-tolerant communication algorithms in general networks. In this context, our work can be viewed as recovering a communication structure in network after accidental failures. Our algorithms are the ﬁrst that span a tree in ad hoc setting, without any pre-processing, in time o ( n ) and using o ( n 2 ) point-to-point messages, for D = o ( n/ log 2 n ) .


Introduction
We consider a message-passing distributed system consisting of n processes, also called nodes, with pairwise different id's.There is an underlying network of point-to-point connections between processes, modeled by an undirected graph G = (V, E).Each node knows only its own id and the id's of its neighbors in the network; this knowledge is however required only for the purpose of distinguishing local ports through which messages are sent.We do not make any specific assumption about the domain of ids, apart that ids are pairwise disjoint and small enough to be contained in messages and to be processed locally.We denote by D the diameter of the underlying network graph G. Computation and communication is in synchronous rounds, each consisting of three parts: receiving messages that have been sent to the node in the previous round (if any), local computation, and sending messages via selected point-to-point links.Each message may carry the original information and a polynomial number of additional bits (our algorithms use in fact O(n 2 log n) additional bits per message).The network is reliable, in the sense that there are no failures or delays in local computations and point-to-point message propagation.
In this work we consider the task of finding a BFS tree (i.e., a spanning tree consisting of some shortest paths from the root to other nodes) in the underlying network.The task occurs in an arbitrary node, while all other nodes are not aware of it.During the computation the network topology does not change.The resulting tree should be rooted at the node in which this task has occurred.Observe that due to ad hoc setting with non-spontaneous wake-ups, i.e., all nodes except the initially awaken one could join the computation only after receiving a message from some node already participating in the execution assumed in this work, a solution to this problem must be distributed.We focus only on deterministic solutions.We consider a single task of building a BFS tree, which occurs in an arbitrary single node. (i)   Our results and the structure of this work.We deliver a deterministic distributed BFS-finding algorithm that trades time for messages.More precisely, our algorithm solves the problem with time complexity O(D • min(D, n/f (n)) • log D • log n) and with the number of point-to-point messages being O(n • (min(D, n/f (n)) + f (n)) • log D • log n), for any monotonically non-decreasing sub-linear integer function f .This yields the first deterministic distributed BFS-finding algorithm in ad hoc networks working in time o(n) and with o(n 2 ) message complexity, for some suitable function f (n) = o(n/ log 2 n), provided D = o(n/ log 4 n).In our algorithm, function f defines the threshold value for node degree, e.g., nodes with degree at most f (n) are treated differently than the other nodes.
Section 2 presents a flooding-like deterministic distributed procedure Shallow Tide, which propagates information along paths of bounded length and bounded node degree, and then collects the information backwards.We use this routine for designing three deterministic distributed algorithms computing a BFS tree in the underlying network G, differing on input specification, c.f., Sections 3 and 4.
Previous and related work.A naive distributed implementation of an algorithm computing a BFS tree in ad hoc network is by flooding a message along all edges of the network and choosing a parent arbitrarily from the senders of the received messages.This approach however requires D rounds and |E| point-topoint messages, which in case of dense graphs gives Θ(n 2 ) message complexity (folklore result).BFS tree can also be built layer by layer, each time by forwarding information about neighborhoods of the front layer nodes to the root, which then computes BFS edges to connect the nodes in the next layer and forwards this information to the nodes in the front layer.This method requires time Θ(D 2 ) and Θ(nD) messages to be sent, which for dense or shallow graphs can be smaller that |E| messages sent by the flooding algorithm.
Another method of spanning a BFS tree is to apply a gathering type of algorithms that collect the information about the underlying network topology in one node and compute a BFS tree locally (see e.g., the monographs Hromkovic et al. (2005); Peleg (2000)).For example, a distributed implementation of a DFS search algorithm gathering such information about the underlying network topology requires Θ(n) rounds and Θ(n) messages to be sent.This result, comparing with the previously described upper bounds, raises the following question, addressed in this work: how the number of messages sent in the process of spanning a BFS tree depends on time complexity.
A BFS tree and other related problems were widely studied in an asynchronous setting, c.f., Awerbuch (1987); Awerbuch andGallager (1985, 1987); Awerbuch et al. (1990).In this model, however, there is no scope for tradeoff between time and message complexity, because there is no notion of rounds.More precisely, a lower bound Ω(|E|) on message complexity was proved in Awerbuch et al. (1990), and a super-linear, in terms of n, lower bound Ω(n log n) was shown in Korach et al. (1989).The problem of efficient maintaining of a BFS tree in dynamic networks was considered in Awerbuch et al. (2008), where the amortized cost of O(n) messages per single change in the topology was obtained.However, we are not aware of any deterministic distributed or randomized solution for the BFS-finding problem (or the related gathering problem) in the model of ad hoc networks with non-spontaneous wake-ups that would achieve both: sublinear time complexity o(n) and subquadratic message complexity o(n 2 ), for any network of diameter o(n/ log 4 n).
Another way of propagating/gathering information is by epidemic broadcast/convergecast Demers et al. (1988).In this method, a node selects a small, typically random, sample among its neighbors to push/pull the information; see also Kempe et al. (2004); Boyd et al. (2006) for other randomized communication algorithms.The problem of finding a BFS tree was considered also in other network settings different from the classic message-passing model.For example, in radio networks, where collisions among messages arriving at the same node at the same round are possible, the problem of deterministic broadcasting (which is no more difficult than building a BFS tree) requires overlinear, in the number of nodes, time, c.f., Chrobak et al. (2006); Clementi et al. (2001).Fault-tolerant communication in networks was also studied in various models and scenarios, see for example Chlebus and Kowalski (2006) for results and references regarding all-to-all communication in fully-connected message passing system with dynamic crashes, Bienkowski et al. (2010) for recovering from crashes in networks of general topology, and Hedetniemi et al. (1988); Hromkovic et al. (2005); Pelc (1996) for a number of fault-tolerant communication algorithms in general networks.In this context, our work can be viewed as recovering a communication structure in network after accidental failures.Our algorithms are the first that span a tree in ad hoc setting, without any pre-processing, in time o(n) and using o(n 2 ) point-to-point messages, for D = o(n/ log 2 n).

Procedure Shallow Tide
One of the common methods of propagating information, especially in case of deterministic protocols, is by flooding, in which each node simply combines and re-sends a newly received information.This method however is not efficient from the perspective of the number of generated point-to-point messages, as in the worst-case scenario all point-to-point links may be used for propagating a single broadcast request.Our flooding-type procedure, called Shallow Tide, first propagates information by building a partial BFS tree on some bounded and shallow part of the network, and then gathers the information backwards toward the source node, all using relatively small number of messages.More precisely, procedure Shallow Tide(s, ℓ, ψ, T ) triggered by a source node s, aims to • wake-up nodes of distance at most ℓ from the source, unless such a node is separated from the source by nodes of degree bigger than ψ that are not initially "known" by the source (i.e., by nodes of degree larger than ψ that are not in the input instance of T ); • build, in a distributed way, a BFS tree rooted at source s on this part of the network; • gather, in the source node s, the information about this tree and all the network links adjacent to nodes in the tree.
SHALLOW TIDE(s, ℓ, ψ, T ) -procedure for node v = s: 1. Round 0: Receive  The procedure is of "wake-up" type, i.e., the source itself triggers the procedure while all other nodes stay dormant until they get a message generated by this procedure run at one of the neighboring nodes.We call all nodes that receive such a message participating nodes.More details follow.
The input of procedure Shallow Tide contains the following parameters: • the source node s initializing the procedure; • upper bound ℓ on the maximal depth of flooding; • threshold value ψ to be compared with the degree of a node in the network; if the degree is bigger than ψ then the received and updated message is not re-sent by that node; • tree T , rooted at node s, being a subgraph of the underlying network.
Additionally, a node v is equipped with set N (v) of neighbors in the underlying network, provided to it as a part of the model setting.
Messages sent in this protocol carry the following information: • round counter: it helps to set the local counter of receiving nodes, according to the round number after starting the procedure at the source node s; initially set by source s to 0; • all input parameters s, ℓ, ψ: in order to be able to initialize the procedure in new nodes; • variable T : an estimate (a subtree) of the BFS tree rooted at s; in the beginning of the protocol, node s initializes it to the corresponding tree T from the input of the procedure; • variable H: a graph being the current local estimate of the underlying network, initially set by source s into ({s} ∪ N (s), {{s, v} : v ∈ N (s)}).
The idea of the procedure is as follows.The source sends a message to all its neighbors in the network in round 0, then it is idle for the next 2ℓ rounds, and in round 2ℓ + 1 it processes the received messages and updates its variables T , H.In the first ℓ rounds, a process v = s that receives a message (counter ′ , s, ℓ, ψ, T ′ , H ′ ) for the first time updates its knowledge about T , H, sets its local counter, and re-sends a message either to its children in T , if it is an internal node in T , or to all its neighbors which were not included in the received graphs H ′ otherwise.This round is called a joining round.Then the node stays idle till the beginning of (2(ℓ − counter) + 1)st round, when it receives messages from its children and re-sends a single message combining the received variables to its selected parent.See Figure 1 for the pseudo-code of procedure Shallow Tide at node s and Figure 2 for the pseudo-code of procedure Shallow Tide at node v = s.

Analysis of procedure Shallow Tide
First note that, by simple inductive argument and the update rule for counter (c.f., steps 1(a), 1(f) and 1(g) in Figure 2), all nodes v = s that receive their first message in round i, for 1 ≤ i ≤ ℓ, set their variables counter to i. Second, observe that all participating nodes, including the source, terminate in round at most 2ℓ + 1. Recall that we call a node participating in Shallow Tide(s, ℓ, ψ, T ) if it receives a message (counter ′ , s, ℓ, ψ, T ′ , H ′ ) in some round.
Denote the initial tree T by T in and the outputted one by T out .Similarly, denote the outputted value of variable H by H out .For any given graph H, let V (H) denote the set of nodes of this graph.Let S be the set of nodes of degree at most ψ for which there exists a path of length at most ℓ from source s containing only nodes in S ∪ V (T in ).More precisely, define recursively: S 0 = {s}; for any i ≥ 1, let S i+1 be the set of nodes v of degree at most ψ in graph G such that there is a path from s to v of length at most ℓ in the subgraph of G induced by the set of nodes S i ∪ V (T in ); let S be the stable point of this construction, that is, set S i such that S i = S i+1 (it exists due to a finite number of nodes in G and by the monotonicity of the recursive construction). to be the set of node Let S * be the set of nodes v such that there is a path of length at most ℓ from s to v in the underlying network, containing nodes in V (T in ) or other nodes of degree at most ψ in the network (end nodes s, v are allowed to have more than ψ neighbors in the network).Note that S * is a union of set S ∪ V (T in ) and the set containing nodes v such that v is a neighbor of some node in S ∪ V (T in ) and there is a path in the underlying network of length at most ℓ from s to v through nodes in S ∪ V (T in ).
The correctness assumption and correctness guarantees for the procedure Shallow Tide(s, ℓ, ψ, T ) are defined as follows: A. Tree T in is a BFS tree on a subgraph of the network G induced by the subset of nodes of distance at most m from the source s, for some m < ℓ.G1.Tree T out is a BFS tree of depth at most ℓ rooted at s in the subgraph of the underlying network induced by nodes in S * .G2.The outputted value of variable H is the subgraph of the network containing nodes in S * together with the edges adjacent to any of these nodes.Shallow Tide(s, ℓ, ψ, T ) -procedure for node v = s: Upon first arrival of message(s) to node v with status dormant: 1. Joining round: Receive: all point-to-point messages (counter ′ , s, ℓ, ψ, T ′ , H ′ ) sent to node v in sending part of the preceding round; Compute: Do the following for the set of received messages containing some value counter ′ , unless it is bigger than ℓ: Send: all point-to-point messages scheduled to be sent in this round; 2. Stay idle for 2 • (ℓ − counter) rounds;

Backward propagation round:
Receive: all point-to-point messages (counter ′ , s, ℓ, ψ, T ′ , H ′ ) sent to node v in sending part of the preceding round; Compute: Do the following for the set of received messages: (a) update local copy of T by adding new nodes and edges from the received copies of T ′ ; update local copy of H by adding new nodes and edges from the received copies of H ′ ; (b) message (counter + 1, s, ℓ, ψ, T , H) is scheduled to be sent to node p(v); Send: point-to-point message scheduled to be sent in this round; 4. Stay idle for counter rounds.Theorem 1 If the initial tree T satisfies the correctness assumption A then (i) Shallow Tide(s, ℓ, ψ, T ) satisfies the correctness guarantees G1 and G2, (ii) all participating nodes terminate in 2ℓ + 2 rounds after starting the procedure at source s, and (iii) the number of point-to-point messages sent by nodes running the procedure is Proof: Assume that the initial tree T in satisfies the correctness assumption A. Consider the set of nodes V (T out ) of the tree outputted by the procedure.Note that the initial tree is a subgraph of the outputted tree, by step 1(e) in Figure 2. It also follows by a straightforward inductive argument based on joining rounds (step 1 in in Figure 2) that all nodes v ∈ S * receive a message by the end of round ℓ.Therefore, they add themselves to the tree T (step 1(e) in Figure 2) and to the graph H (step 1(d) in Figure 2; in case of H, also the adjacent edges are added) during one of these rounds, mainly, in the first round they receive a message (joining round).The path along which the message has been propagated from s to v is the shortest one via the subgraph induced by nodes in V (T in ) ∪ S, by the fact that T in is a BFS tree on a subgraph induced by some set of nodes, while node v itself is in set S * (which contains set V (T in )∪S and some of its adjacent nodes).It remains to note that in rounds ℓ + 1, . . ., 2ℓ, the information is propagated backwards from such nodes v to the source.Hence it reaches the source, which updates both variables.This completes the proof of correctness guarantees G1 and G2.
Suppose that the correctness assumption is satisfied.Observe that the total number of point-to-point messages sent in an execution of the procedure Shallow Tide(s, ℓ, ψ, T ) by the participating nodes is Indeed, the number of point-to-point messages sent by internal nodes in T in is at most 2|V (T in )|, c.f., steps 1(f) and 3(b) in Figure 2. The number of messages sent by other nodes is at most

BFS Algorithm
The main tool delivered in this paper is a deterministic distributed algorithm finding a BFS tree in ad hoc network with non-spontaneous wake-ups.We first give an algorithm parametrized by an additional integer ψ, which illustrates the main ideas developed in this paper.Next we analyze the correctness and complexity of this algorithm, with respect to network parameters n, D and the input parameter ψ.Finally, we extend this algorithm so that instead of independent parameter ψ there is a function f as a part of the input, which in turn gets rid of parameter ψ from the complexity formulas.

Parametrized BFS algorithm
We call our first algorithm BFS by Tides; Figure 3 shows the pseudo-code of BFS by Tides(s, ψ).
There are two input parameters of this algorithm: a source s, and an integer parameter ψ.The algorithm uses the following variables: BFS by Tides(s, ψ) let H stand for the outputted graph and let T be the outputted tree; • termination -a boolean variable, initially set to f alse, indicating whether a termination condition holds; it is checked by the source node s; • κ -a non-negative integer; its value is not decreasing, and intuitively it stores the depth until which the underlying network is fully known by the source s; • λ -a non-negative integer, which, when increased by 1, doubles the range for learning new nodes and links in the network; • T -a tree, monotonically non-decreasing (in the sense of inclusion), which is used as starting point to improve the estimate of the final BFS tree; initialized to node s and its neighbors with the edges connecting the neighbors with s; • H -local estimate of the final network topology; • C -a set of newly visited nodes during the current run of procedure Shallow Tide, of degree bigger than ψ in the underlying network.
The output is the BFS tree T on the whole network, rooted at s, and graph H illustrating the whole topology of the underlying network.They are initialized by the source node and they are modified in the course of the algorithm so that their final values in the termination round are returned as the output at the source node s.
The idea of the algorithm is as follows.The external loop (step 2 in the pseudo-code in Figure 3) is run until no new node is discovered, i.e., variable termination is set to true.Within a single run of this loop, an internal loop is executed (step 2(b) in the pseudo-code), which runs the procedure Shallow Tide on subsequently increased depths ℓ = κ + 2 λ , until the algorithm discovers a new node in T with degree bigger than ψ, i.e., when C = ∅.Then the range κ -within which the source knows the full topology of the network -is updated to be the distance to the closest of such discovered nodes (measured in the current topology-estimate graph H), as so the estimate of the BFS tree T becomes up to depth κ + 1; all these changes are done in step 2(c), provided there are still unvisited nodes (i.e., V (T ) = V (H)).

Analysis of algorithm BFS by Tides
We argue about correctness, termination and complexity of algorithm BFS by Tides(s, ψ), for any node s and positive integer ψ.Before starting the actual analysis, observe that the computation specified in points 2(b)iii and 2(c) is actually done by the root, and is based on the graph H returned by the last execution of routine Shallow Tide. (ii)  Correctness is guaranteed by the following properties.If the algorithm terminates, it must have V (T ) = V (H) confirmed in step 2(b).iii.By Theorem 1, the execution of Shallow Tide(s, κ + 2 λ , ψ, T ) in the preceding step 2(b).iisatisfies correctness guarantees G1 and G2, provided the correctness assumption A holds.This is assured by a straightforward induction argument on the number of executions of Shallow Tide.By guarantee G2 and by V (T ) = V (H), there are no other edges outgoing from the set of nodes V (T ) in the underlying network, and therefore the outputted T is a spanning tree.It is also a BFS tree on the set of (all) nodes V (T ), by the guarantee G1.By definition of κ and guarantee G2, tree T obtained in step 2(c).ii is a BFS tree of depth κ + 1 in the whole graph G. Therefore, by induction, the assumption A holds in every iteration.This completes the proof of correctness.
Termination follows from the following two observations.First, each internal loop 2(b) terminates eventually, since in each iteration parameter λ increases by one, and thus, by the correctness of the algorithm and the routine Shallow Tide(s, κ + 2 λ , ψ, T ) (c.f., Theorem 1), the outputted tree T spans the whole network.This results in V (T ) = V (H) and consequently termination being set to true, unless the loop has finished earlier by the condition C = ∅ being satisfied.Moreover, after each such termination, an integer variable κ is increased by at least 1.Since κ cannot be bigger than D, as otherwise we would get V (T ) = V (H) after an execution of subroutine Shallow Tide, the number of iterations of the external loop is bounded.Hence we proved the following.Theorem 3 follows from Lemma 2 and from Lemmas 5 and 6. Figure 5 illustrates an example of tree T , graph H, set C, distances κ and ℓ = κ + 2 λ during an execution of BFS by Tides on network G.
For the purpose of the complexity analysis, we introduce the following terminology: • let T k,i be the tree T computed by the subroutine Shallow Tide(s, κ, ψ, T ) (step 2(b).ii of the pseudo-code) when κ = k and λ = i; • let H k,i be the graph H computed by the subroutine Shallow Tide(s, κ, ψ, T ) (step 2(b).ii of the pseudo-code) when κ = k and λ = i.

Time complexity
We give more accurate estimate of the time complexity of algorithm BFS by Tides.

Lemma 4
The number of single runs of the external loop of algorithm BFS by Tides(s, ψ) is bounded above by min(D, 3n/ψ), where n is the actual number of nodes and D is the diameter of the network.Proof: It is enough to estimate the number of exits from the internal loop, and more precisely, the number of different BFS levels on which a node of degree bigger than ψ is discovered.(Note that setting termination to true in step 2(b).iiiautomatically results in finishing the algorithm after the next few lines of local computation.)In one way, the number of different BFS levels in the network, starting from the source node s, containing nodes with degree bigger than ψ (in the network) is bounded naturally by network diameter D.
On the other hand, let L 1 , L 2 , . . ., L x be a sequence of different BFS levels containing nodes with degree bigger than ψ in the network.Let s j , for 1 ≤ j ≤ x, be such a node in L j of degree bigger than ψ.Observe that any node can be a neighbor of at most three such nodes s j , mainly the one located in the same BFS layer and the other two located in the preceding and in the succeeding layers, if any.Hence, the sum |N (s 1 )| + |N (s 2 )| + . . .+ |N (s x )| is bounded above by 3n.Consequently, the number x of different levels containing nodes with degree bigger than ψ is bounded from above by 3n/ψ.✷ Lemma 5 Time complexity of algorithm BFS by Tides is O(D • min(D, n/ψ) • log D), where n is the actual number of nodes and D is the diameter of the network.
Proof: By Lemma 4, the number of single runs of the external loop of algorithm BFS by Tides(s, ψ) is bounded above by min(D, 3n/ψ).
It remains to estimate the number of rounds taken by subsequent executions of the internal loop in step 2. Note that a single run of the internal loop takes 2 • (κ + 2 λ ) + 2, by Theorem 1.It follows from the structure of the internal loop, mainly from the fact that the parameter 2 λ grows exponentially and it cannot be bigger than D, that there are at most log D of executions of procedure Shallow Tide, with different parameters, within one execution of the internal loop 2(b).Each such execution takes O(D) rounds, since again the value of 2 • (κ + 2 λ ) + 2 is O(D) (otherwise we get V (T ) = V (H) and terminate immediately).
Therefore, a single run of the external loop takes O(D log D) rounds, which combined with Lemma 4 completes the proof.✷ Proof: Partition the set of point-to-point messages sent during the execution of BFS by Tides(s, ψ) into two categories.First category contains messages that are sent in steps 1f and 3b of routine Shallow Tide(s, ℓ, ψ, T ) by nodes v (c.f., Figure 2), which is executed in step 2(b).ii of the pseudo-code.

Message complexity
We call this type of messages tree messages.Second category consists of messages that are sent in step 1g of routine Shallow Tide(s, ℓ, ψ, T ) by nodes v = s (c.f., Figure 2), which is executed in step 2(b).ii of the pseudo-code.We call this type of messages searching messages.
First we estimate the number of tree messages.By Lemma 4, the number of single runs of the external loop of algorithm BFS by Tides(s, ψ) is O(min(D, n/ψ)).The number of iterations in the internal loop is at most log D, by the upgrade rule for λ and the upper bound D on 2 λ (otherwise we would get V (T ) = V (H) and terminate).Hence, the total number of executions of routine Shallow Tide in step 2(b).ii is bounded from above by O(min(D, n/ψ) • log D).Each tree message corresponds to a single edge from tree T being the input of the routine Shallow Tide during which the message was sent.Observe that in a single execution of Shallow Tide in step 2(b).ii each edge from tree T is used twice: in step 1f and in step 3b.Hence, the total number of tree messages used during a single execution of routine Shallow Tide is O(n), and consequently, the total number of tree messages in the whole execution of BFS by Tides(s, In the remainder of the proof we bound the total number of searching messages.Observe that in each step 1g of routine Shallow Tide(s, ℓ, ψ, T ) a node sends at most ψ point-to-point messages and in step 3b only one message.We show that any node v sends searching messages in at most log D rounds in the execution, i.e., at most log D times node v executes step 2(b).ii of the pseudo-code of BFS by Tides, triggering routine Shallow Tide.This will automatically imply the upper bound O(n • ψ • log D) for the total number of searching messages.
Note that node s does not send searching messages, as tree T always contains all its adjacent edges in network G. Consider node v = s.Let k j , i j , for a positive integer j, be the values of variables κ, λ, respectively, when v sends searching messages for the j-th time during the execution of BFS by Tides(s, ψ).More precisely, each such j-th sending of searching messages by node v happens when it participates in the execution of the routine Shallow Tide(s, k j + 2 ij , ψ, T ) in step 2(b).ii of the pseudo-code of BFS by Tides(s, ψ), when it runs its step 1g of the routine.Observe that there is at most one run of step 1g by a node in any execution of routine Shallow Tide.Moreover, only nodes that are not internal in the input instance of T may send any searching message within routine Shallow Tide.
We first argue that the sequence (k j ) j is increasing.Indeed, it is non-decreasing by the fact that the value of variable κ is non-decreasing in time.Suppose, to the contrary, that k j = k j+1 , for some i.It follows that 1 ≤ i j < i j+1 ≤ D.Moreover, the routine Shallow Tide(s, k j+1 + 2 ij+1 , ψ, T kj+1,ij+1 ) is executed after Shallow Tide(s, k j + 2 ij , ψ, T kj ,ij ) but within the same execution of step 2(b) of the pseudo-code, and therefore tree T kj+1,ij+1 contains the tree outputted by the routine Shallow Tide(s, k j + 2 ij , ψ, T kj ,ij ).In particular, T kj+1,ij+1 contains node v as internal node, by specification of step 1g (mainly, the fact that counter < ℓ = k j + 2 ij ) run during the execution of Shallow Tide(s, k j + 2 ij , ψ, T kj ,ij ).It follows that v cannot send a searching message in the following executions of Shallow Tide for parameter κ = k j+1 , in particular for λ = i j+1 , as it is an internal node in their input instances of tree T ; thus we get a contradiction, which completes the proof that the sequence (k j ) j is increasing.
It remains to argue that the sequence (i j ) j is decreasing and within the range [1, log D].The range follows from the same argument as given in the estimate of the number of tree messages.Suppose that i j = i j+1 , for some j.We already argued that k j < k j+1 .It follows from the fact that set C was empty after the execution of Shallow Tide(s, k On the other hand, the shortest path from s to v in network G is at most k j + 2 ij , since v participates in the execution of Shallow Tide(s, k j + 2 ij −1 , ψ, T kj ,ij −1 ).These two facts together yield that node v must have been added to set T as an internal node during Shallow Tide(s, k j + 2 ij −1 , ψ, T kj ,ij −1 ), and consequently it could not send any message during Shallow Tide(s, k j + 2 ij −1 , ψ, T kj ,ij −1 ).We obtained a contradiction, proving that the sequence (i j ) j is decreasing and within the range [1, log D].Hence the number of rounds in which node v sends searching messages is at most log D. ✷

BFS algorithm with complexity formula being a function of n and D only
The complexity of algorithm BFS by Tides(s, ψ) depends on the input parameter ψ, which is independent of the actual number of nodes n.We show how to modify algorithm BFS by Tides and then how to iterate the obtained algorithm to adapt to the number n, in the sense that the complexity of the obtained solution will be expressed only as a function on network parameters n, D. Recall that these parameters are not a priori known to the nodes, therefore the resulting algorithm must estimate their values during the execution and act accordingly.
Algorithm Bounded BFS.We first show how to modify algorithm BFS by Tides according to our needs of further elimination of parameter ψ.This modification still uses ψ as parameter, however it helps to control the number of discovered nodes and terminate as soon as this number becomes bigger than some input parameter n * .We call the modified algorithm Bounded BFS, and run with three input parameters: s, ψ, n * .The pseudo-code of the algorithm Bounded BFS(s, ψ, n * ) differs from the pseudo-code of BFS by Tides(s, ψ) in two details.The first difference is in executing the following step instead of step 2(b).iii: Our technique is even more general, and establishes a tradeoff between time and message complexity functions.There is still a gap between our time-message complexity tradeoff and natural lower bound D on time and Ω(n) on message complexity.As far as we know these are the best known lower bounds on the corresponding complexity measures when considering them separately, but it is not clear whether similar bounds can be matched simultaneously by a single algorithm.Recall that the former bound is matched by a naive flooding, in the cost of Ω(n 2 ) messages, while the latter bound is matched by a DFSlike search algorithm collecting the whole knowledge about the underlying graph in linear time Θ(n) (independent on D).Our final deterministic distributed solution is close to the lower bounds by factors roughly O(f (n) polylog n) and O(n/f (n) polylog n), for some suitable functions f (•).
here the first and the second parts follow from steps 1(g) and 3(b) in Figure 2, respectively.Since |S * | = |V (T out )|, and since the number of messages sent by the source s in round 0 is at most |V (T out )| = |V int (T in )| + |V (T out ) \ V int (T in )|, by the correctness guarantee G1, we get the desired formula for the message complexity.✷

Fig. 3 :
Fig. 3: Algorithm BFS by Tides(s, ψ): pseudo-code for the source node s; all other nodes only participate in the runs of procedure Shallow Tide triggered by s during the execution of BFS by Tides(s, ψ).

Figure 4 Fig. 4 :
Fig.4: An example of three steps of an execution of algorithm BFS by Tides: (a) tree T before executing procedure Shallow Tide in step 2(b).ii of the pseudo-code; (b) messages (directed) sent during the succeeding execution of Shallow Tide, for distance parameter ℓ = κ + 2 λ and tree T from picture (a); (c) newly learnt graph H with nonempty set C of newly discovered nodes of degree bigger than ψ (black nodes); here κ is the distance from the source s to the closest node in C (c.f., step 2(c).i of the pseudo-code); (d) newly defined tree T , based on graph H and parameter κ + 1 (step 2(c).ii of the pseudo-code).

Lemma 2
Algorithm BFS by Tides(s, ψ) is correct and terminates.Theorem 3 If the number of nodes in network G is n and the diameter of the network is D then (i) the algorithm BFS by Tides(s, ψ) computes a BFS tree, rooted at s, on the whole network, (ii) all nodes terminate in O(D • min(D, n/ψ) • log D) rounds after starting the algorithm at source s, and (iii) the number of point-to-point messages sent by nodes running the algorithm is O(n • min(D, n/ψ) • log D + nψ log D).

Fig. 5 :
Fig. 5: An example of variables κ, ℓ = κ + 2 λ , T , H and C in a single round of execution BFS by Tides on network G at source node s.Here ψ = 4. Recall that T is a subgraph of H and H is a subgraph of G.

Lemma 6
The total number of point-to-point messages sent during the algorithm BFS by Tides(s, ψ) is O(n • min(D, n/ψ) • log D + nψ log D), where n is the actual number of nodes and D is the diameter of the network.

2D
(b).iii* : If V (T ) = V (H) or |V (H)| > n * then termination ← true else C ← {v : v ∈ V (H) \ V int (T ) & |N H (v)| > ψ};It can be easily observed that the only difference between the original step 2(b).iii of algorithm BFS by Tides(s, ψ) and its counterpart (the above step 2(b).iii*) in algorithm Bounded BFS(s, ψ, n * ) is the additional alternative condition |V (H)| > n * yielding termination (i.e., setting variable termination to true).The second difference between the two algorithms is that in Bounded BFS we also output the topology-estimate graph H, as it can be further useful in the design of our final BFS algorithm.We require from Bounded BFS(s, ψ, n * ) to satisfy the following conditional correctness guarantee: rithm Bounded BFS(s, f (n * ), n * ), where n * is a power of 2, that the time complexity of algorithmFinal BFS(s, f ) is at most • min(D, 2 j /f (2 j )) • log D   , which is O(D • min(D, n/f (n)) • log D • log n) in case of x f (x) being a non-decreasing function of x. (iii) Message complexity of algorithm Final BFS is O ((n • min(D, n/f (n)) • log D + nf (n) log D) • log n)by the similar argument as used in the analysis of time complexity of Final BFS and by the fact that x/f (x) is a non-decreasing function.✷5 ConclusionWe achieved o(n) time complexity and o(n 2 ) message complexity for the problem of spanning a BFS tree in ad hoc networks with diameter D = D(n) = o(n/ log 4 n), e.g., by setting f (n) = nD(n).
counter ← the smallest received counter ′ ; (b) create local variable T by adding nodes and edges from the received copies of T ′ ; create local variable H by adding nodes and edges from the received copies of H ′ ; (c) A ← N (v) \ V (H); (d)update H by adding nodes from {v} ∪ N (v) and edges between v and N (v), if they are not in H; (e) if v in T then p(v) ← the parent of v in T ; else p(v) ← the node with the smallest id among those from which v received a message in the current round and add node v and edge {v,