key: cord-0581937-mno3xcs2 authors: Luna, Giuseppe A. Di; Viglietta, Giovanni title: Computing in Anonymous Dynamic Networks Is Linear date: 2022-04-05 journal: nan DOI: nan sha: e7a9fce486e6b41c2a8c1b1caca7a60866b9bdde doc_id: 581937 cord_uid: mno3xcs2 We give the first linear-time terminating counting algorithm for processes in anonymous 1-interval-connected dynamic networks with a leader. As a byproduct, we are able to compute in $3n$ rounds emph{every} function that is computable deterministically in such networks. If explicit termination is not required, the running time improves to $2n$ rounds, which we show to be optimal up to a small additive constant (this is also the first non-trivial lower bound for counting). As our main tool of investigation, we introduce a combinatorial structure called emph{history tree}, which is of independent interest. This makes our paper completely self-contained, our proofs elegant and transparent, and our algorithms straightforward to implement. In recent years, considerable effort has been devoted to the design and analysis of counting algorithms for anonymous 1-interval-connected networks with a leader. A series of increasingly sophisticated works, mostly based on classical mass-distribution techniques, have recently led to a celebrated counting algorithm in $O({n^{4+ epsilon}} log^{3} (n))$ rounds (for $epsilon>0$), which was the state of the art prior to this paper. Our contribution not only opens a promising line of research on applications of history trees, but also demonstrates that computation in anonymous dynamic networks is practically feasible, and far less demanding than previously conjectured. approach of implementing a mass-distribution mechanism similar to the local averaging used to solve the average consensus problem [16, 38, 43] . (In Appendix D we give a comprehensive survey. ) We point out that the mass-distribution approach requires processes to exchange numbers whose representation size grows at least linearly with the number of rounds. Thus, all previous works on counting in anonymous 1-interval-connected networks need messages of size at least Ω(n 4 ). In spite of the technical sophistication of this line of research, there is still a striking gap in terms of running time-a multiplicative factor of O(n 3 log 3 (n))-between the best algorithm for anonymous networks and the best algorithm for networks with unique IDs. The same gap exists with respect to static anonymous networks, where the Counting problem is known to be solvable in 2n rounds [34] . Given the current state of the art, solving non-trivial problems in large-scale dynamic networks is still impractical. Main results. In this paper, we close the aforementioned gaps by showing that counting in 1-interval-connected anonymous dynamic networks with a leader is linear: we give a deterministic algorithm for the Counting problem that terminates in 3n − 2 rounds (Theorem 4.10), as well as a non-terminating algorithm that stabilizes on the correct count in 2n − 2 rounds (Theorem 4.4). We also prove a lower bound of roughly 2n rounds, both for terminating and stabilizing counting algorithms (Theorem 5.2); this is the first non-trivial lower bound for anonymous networks (better than n − 1), and it shows that our stabilizing algorithm is optimal up to a small additive constant. In addition, our algorithms support network topologies with multiple parallel links and self-loops (i.e., multigraphs, as opposed to the simple graphs used in traditional models). Significance. Our algorithms actually solve a generalized version of the Counting problem: when processes are assigned inputs, they are able to count how many processes have each input. Solving such a Generalized Counting problem allows us to solve a much larger class of problems, called multi-aggregation problems, in the same number of rounds (Theorem 2.1). On the other hand, these are the only problems that can be solved deterministically in anonymous networks (Theorem 5.1). Thus, we come to an interesting conclusion: In 1-interval-connected anonymous dynamic networks with a leader, any problem that can be solved deterministically has a solution in at most 3n − 2 rounds. Our lower bounds show that there is an overhead to be paid for counting in anonymous dynamic networks compared to networks with IDs, but the overhead is only linear. This is much less than what was previously conjectured [26, 28] ; in fact, our results make computations in anonymous and dynamic large-scale networks possible and efficient in practice. We remark that the local computation time and the amount of processes' internal memory required by our algorithms is only polynomial in the size of the network. Also, like in previous works, processes need to send messages of polynomial size. Technique. Our algorithms and lower bounds are based on a novel combinatorial structure called history tree, which completely represents an anonymous dynamic network and naturally models the idea that processes can be distinguished if and only if they have different "histories" (Section 3). Thanks to the simplicity of our technique, this paper is entirely self-contained, our proofs are transparent and easy to understand, and our algorithms are elegant and straightforward to implement. 1 We argue that history trees are of independent interest, as they could help in the study of different network models, as well as networks with specific restricted dynamics. Here we give some informal definitions; the interested reader may find rigorous ones in Appendix A. Dynamic network. Our model of computation involves a system of n anonymous processes in a 1-interval-connected dynamic network whose topology changes unpredictably at discrete time units called rounds. That is, at round t ≥ 1, the network's topology is modeled by a connected undirected multigraph G t whose edges are called links. Processes can send messages through links and can update their internal states based on the messages they receive. Round structure. Each round is subdivided into two phases: in the message-passing phase, each process broadcasts a message containing (an encoding of) its internal state through all the links incident to it. After all messages have been exchanged, the local-computation phase occurs, where each process updates its own internal state based on a function A of its current state and the multiset of messages it has just received. Processes are anonymous, implying that the function A is the same for all of them. We stress that all local computations are deterministic. Input and output. At round 0, each process is assigned an input, which is deterministically converted into the process' initial internal state. Furthermore, at every round, each process produces an output, which is a function of its internal state. Some states are terminal ; once a process enters a terminal state, it can no longer change it. Stabilization and termination. A system is said to stabilize if the outputs of all its processes remain constant from a certain round onward; note that a process' internal state may still change even when its output is constant. If, in addition, all processes reach a terminal state, the system is said to terminate. A solves a given problem if, whenever the processes are assigned a certain multiset of n inputs, and all processes execute A in their local computations, the system eventually stabilizes on the correct multiset of n outputs. Note that the same algorithm A must work for all n ≥ 1 (i.e., the system is unaware of its own size) and regardless of the network's topology (as long as it is 1-interval-connected). A stronger notion of solvability requires that the system not only stabilizes but actually terminates on the correct multiset of outputs. Unique leader. A commonly made assumption is the presence of a unique leader in the system. This can be modeled by assuming that each process' input includes a leader flag, and an input assignment is valid if and only if there is exactly one process whose input has the leader flag set. Multi-aggregation problems. A multi-aggregation problem is a problem where the output to be computed by each process only depends on the process' own input and the multiset of all processes' inputs. In the special case where all processes have to compute the same output, we have an aggregation problem. Notable examples of aggregation problems include computing statistical functions on input numbers, such as sum, average, maximum, median, mode, variance, etc. As we will see, the multi-aggregation problems are precisely the problems that can be solved in 1-interval-connected anonymous dynamic networks with a unique leader. Specifically, in Section 4 we will show that all multi-aggregation problems can be solved in a linear number of rounds. On the other hand, in Section 5 we will prove that no other problem can be solved at all. Counting problem. An important aggregation problem is the Generalized Counting problem, where each process must output the multiset of all processes' inputs. That is, the system has to count how many processes have each input. In the special case where all (non-leader) processes have the same input, this reduces to the Counting problem: determining the size of the system, n. Completeness. The Generalized Counting problem is complete for the class of multi-aggregate problems (no matter if the network is connected or has a unique leader), in the following sense: Theorem 2.1. If the Generalized Counting problem can be solved (with termination) in f (n) rounds, then every multi-aggregate problem can be solved (with termination) in f (n) rounds, too. Proof. Once a process with input x has determined the multiset µ of all processes' inputs, it can immediately compute any function of (x, µ) within the same local-computation phase. We introduce history trees as a natural tool of investigation for anonymous dynamic networks. An example of a history tree is illustrated in Figure 1 , and a formal definition is found in Appendix B. Indistinguishable processes. Since processes are anonymous, they can only be distinguished by their inputs or by the multisets of messages they have received. This leads to an inductive definition of indistinguishability: Two processes are indistinguishable at the end of round 0 if and only if they have the same input. At the end of round t ≥ 1, two processes p and q are indistinguishable if and only if they were indistinguishable at the end of round t − 1 and, for every equivalence class A of processes that were indistinguishable at the end of round t − 1, both p and q receive an equal number of (identical) messages from processes in A at round t. Levels of a history tree. A history tree is a structure associated with a dynamic network. It is an infinite graph whose nodes are subdivided into levels L −1 , L 0 , L 1 , L 2 , . . . , where each node in level L t , with t ≥ 0, represents an equivalence class of processes that are indistinguishable at the end of round t. The level L −1 contains a unique node r, representing all processes in the system. Each node in level L 0 has a label indicating the (unique) input of the processes it represents. Black and red edges. A history tree has two types of undirected edges; each edge connects nodes in consecutive levels. The black edges induce an infinite tree rooted at r and spanning all nodes. A black edge {v, v }, with v ∈ L t and v ∈ L t+1 , indicates that the child node v represents a subset of the processes represented by the parent node v. The red multiedges represent messages. A red edge {v, v } with multiplicity m, with v ∈ L t and v ∈ L t+1 , indicates that, at round t + 1, each process represented by v receives a total of m (identical) messages from processes represented by v. Anonymity of a node. The anonymity a(v) of a node v of a history tree is defined as the number of processes represented by v. Since the nodes in a same level represent a partition of all the processes, the sum of their anonymities must be n. Moreover, by the definition of black edges, the anonymity of a node is equal to the sum of the anonymities of its children. Observe that the Generalized Counting problem can be rephrased as the problem of determining the anonymities of all the nodes in L 0 . History of a process. A monotonic path in the history tree is a sequence of nodes in distinct levels, such that any two consecutive nodes are connected by a black or a red edge. We define the view of a node v in the history tree as the finite subgraph induced by all the nodes spanned by monotonic paths with endpoints v and r. The history of a process p at round t is the view of the (unique) node in L t that represents a set of processes containing p. Fundamental theorem. Intuitively, the history of a process at round t contains all the information that the process can use at that round for its local computations. This intuition is made precise by the following fundamental theorem (a rigorous proof is found in Appendix B.3): Figure 1 : The first rounds of a dynamic network with n = 12 processes and the corresponding levels of the history tree. The letters L, A, B indicate processes' inputs (the process with input L is the leader). At each round, the network's links are represented by solid red edges. Sets of indistinguishable processes are indicated by dashed blue lines and unique labels. The same labels are also reported in the history tree: each node corresponds to a set of indistinguishable processes. It should be noted that labels other than L, A, B are not part of the history tree itself, and have been added for the reader's convenience. The dashed red edges in the history tree represent messages received by processes through the links; the numbers indicate their multiplicities (when greater than 1). For example, the edge {c 2 , b 4 } has multiplicity 2 because, at round 3, each of the two processes in the class c 2 receives two identical messages from the (indistinguishable) processes that were in the class b 4 in the previous round. On the other hand, the node labeled c 5 represents four processes (i.e., its anonymity is 4) at round 3; among them, only one receives a message from c 6 in the next round. Thus, this process is disambiguated, which causes the node c 5 to branch into two nodes: d 7 , with anonymity 3, and d 8 , with anonymity 1. The view of the node labeled b 3 is the subgraph of the history tree induced by the nodes with labels in the set {b 3 , a 3 , a 5 , L, A, B, r}. Theorem 3.1. The state of a process p at the end of round t is determined by a function F A of the history of p at round t. The mapping F A depends entirely on the algorithm A; it does not depend on p, on t, on the network's topology, nor on the inputs assigned to the processes at round 0. Locally constructing the history. The significance of Theorem 3.1 is that it allows us to shift our focus from dynamic networks to history trees. As shown in Appendix B.4, there is a local algorithm A * that allows processes to construct and update their history at every round. Thanks to Theorem 3.1, processes are guaranteed not to lose any information if they simply execute A * , regardless of their goal, and then compute their outputs as a function of their history. Thus, in the following, we will assume without loss of generality that a process' internal state at every round, as well as all the messages it broadcasts, always coincide with its history at that round. As discussed at the end of Section 3, the following algorithms assume that all processes have their current history as their internal state and broadcast their history through all available links at every round. We will show how to solve the Generalized Counting problem in such a setting. In a history tree (or in a view), a node v is said to be non-branching if it has exactly one child, which we denote as c(v). Recall that the parent-child relation is determined by black edges only. A pair of non-branching nodes (v 1 , v 2 ) in a history tree is said to be exposed with multiplicity (m 1 , m 2 ) if the red edge {c(v 1 ), v 2 } is present with multiplicity m 1 ≥ 1, while the red edge {c(v 2 ), v 1 } has multiplicity m 2 ≥ 1 (see Figure 2 , left). Note that v 1 and v 2 must be on the same level. Thanks to the following lemma, if we know the anonymity of a node in an exposed pair, we can determine the anonymity of the other node. (Recall that we denote the anonymity of v by a(v).) Lemma 4.1. If (v 1 , v 2 ) is an exposed pair with multiplicity (m 1 , m 2 ), then a(v 1 ) · m 1 = a(v 2 ) · m 2 . Proof. Let v 1 , v 2 ∈ L t , and let P 1 and P 2 be the sets of processes represented by v 1 and v 2 , respectively. Since v 1 is non-branching, we have a(c(v 1 )) = a(v 1 ), and therefore c(v 1 ) represents P 1 , as well. Hence, the number of links between P 1 and P 2 in G t+1 (counted with their multiplicities) is a(c(v 1 )) · m 1 = a(v 1 ) · m 1 . By a symmetric argument, this number is equal to a(v 2 ) · m 2 . Lemma 4.2. Let P be a set of processes in a 1-interval-connected dynamic network of size n, such that 1 ≤ |P | ≤ n − 1, and let t ≥ 0. Then, at every round t ≥ t + |P |, in the history of every process there is a node at level L t representing at least one process not in P . Proof. Let Q be the complement of P (note that Q is not empty), and let Q t+i be the set of processes represented by the nodes in L t+i whose view contains a node in L t representing at least one process in Q. We will prove by induction that |Q t+i | ≥ |Q| + i for all 0 ≤ i ≤ |P |. The base case holds because Q t = Q. The induction step is implied by Q t+i Q t+i+1 , which holds for all 0 ≤ i < |P | as long as |Q t+i | < n. Indeed, because G t+i+1 is connected, it must contain a link between a process p ∈ Q t+i and a process q / ∈ Q t+i . Thus, the history of q at round t + i + 1 contains the history of p at round t + i, and so Q t+i Q t+i ∪ {q} ⊆ Q t+i+1 . Now, plugging i := |P |, we get |Q t+|P | | = n. In other words, the history of each node in L t+|P | (and hence in subsequent levels) contains a node at level L t representing a process in Q. It is well known that, in a 1-interval-connected network, any piece of information can reach all processes in n − 1 rounds [30] . We can translate this observation into the language of history trees: In the history tree of a 1-interval-connected dynamic network, every node at level L t is in the view of every node at level L t , for all t ≥ t + n − 1. Proof. Let v ∈ L t , and let P be the set of processes not represented by v. If P is empty, then all nodes in L t are descendants of v, and have v in their view. Otherwise, 1 ≤ |P | ≤ n − 1, and Lemma 4.2 implies that v is in the view of all nodes in L t . Theorem 4.4. There is an algorithm that solves the Generalized Counting problem in 1-intervalconnected anonymous dynamic networks with a leader and stabilizes in at most 2n − 2 rounds. Proof. Let n > 1, and let L T be the first level of the history tree whose nodes are all non-branching. Since |L 0 | ≥ 2 and |L t−1 | ≤ |L t | ≤ n for all t ≥ 0, we have T ≤ n − 2 by the pigeonhole principle. Let ∈ L T be the node corresponding to the leader; we know that a( ) = 1. Since G T +1 is connected, the exposed pairs of nodes in L T must form a connected graph on L T , as well. Hence, thanks to Lemma 4.1, any process that has complete knowledge of L T and L T +1 can use the information that a( ) = 1 to compute the anonymities of all nodes in L T . In fact, by Corollary 4.3, every process is able to do so by round (T + 1) + n − 1 ≤ 2n − 2. Summarizing, the local algorithm for each process is as follows: Find the first level in your history whose nodes are all non-branching. If such a level exists and contains a node corresponding to the leader, assume this is L T and compute the anonymities of all its nodes. Then add together the anonymities of nodes having equal inputs, and give the result as output. Even if some outputs may be incorrect at first, the whole system stabilizes on the correct output by round 2n − 2. If we were to use the same strategy of Theorem 4.4 to devise a terminating algorithm, we would be bound to fail, as shown by the counterexample in Appendix C.1. The problem is that a process has no easy way of knowing whether the first level in its history whose nodes are all non-branching is really L T , and so it may end up terminating too soon with the wrong output. To find a correct terminating condition, we will have to considerably develop the theory of history trees. Guessing anonymities. Inspired by Lemma 4.1, we now describe a more sophisticated way of estimating the anonymity of a node based on known anonymities (see Figure 2 , center). Let u be a node of a history tree, and assume that the anonymities of all its children u 1 , u 2 , . . . , u k are known: such a node u is called a guesser. If v is not a child of u and the red edge {v, u} is present with multiplicity m ≥ 1, we say that v is guessable by u. In this case, we can make a guess g(v) on the anonymity of v: where m i is the multiplicity of the red edge {u i , v } for all 1 ≤ i ≤ k, and v is the parent of v (possibly, m i = 0). Although a guess may be inaccurate, it never underestimates the anonymity: Proof. Let u, v ∈ L t , and let P 1 and P 2 be the sets of processes represented by u and v , respectively. By counting the links between P 1 and P 2 in G t+1 in two ways, where the two sums range over all children of u and v , respectively (note that v = v j for some j), and m i is the multiplicity of the red edge {v i , u} (so, m = m j ). Our lemma easily follows. Heavy nodes. Even if a node is guessable, it is not always a good idea to actually assign it a guess. For reasons that will become apparent in Lemma 4.6, our algorithm will only assign guesses in a well-spread fashion, i.e., in such a way that at most one node per level is assigned a guess. Suppose now that a node v has been assigned a guess. We define its weight w(v) as the number of nodes in the subtree hanging from v that have been assigned a guess (this includes v itself). Recall that subtrees are determined by black edges only. We say that v is heavy if w(v) ≥ g(v). Lemma 4.6. In a well-spread assignment of guesses, if w(v) > a(v), then some descendants of v are heavy (the descendants of v are the nodes in the subtree hanging from v other than v itself ). Proof. Our proof is by contradiction and by well-founded induction on w(v). Let v 1 , v 2 , . . . , v k be the "immediate" descendants of v that have been assigned guesses. That is, for all 1 ≤ i ≤ k, no internal nodes of the black path with endpoints v and v i have been assigned guesses. By the basic properties of history trees, a(v) ≥ i a(v i ). Also, the induction hypothesis implies Let v d be the deepest of the v i 's, which is unique, since the assignment of guesses is well spread. Note that v d has no siblings at all, otherwise we would have a(v) > i a(v i ). Due to Lemma 4.5, we conclude that g(v d ) = a(v d ) = w(v d ), and so v d is heavy. Correct guesses. We say that a node v has a correct guess if v has been assigned a guess and g(v) = a(v). The next lemma gives a criterion to determine if a guess is correct. Lemma 4.7. In a well-spread assignment of guesses, if a node v is heavy and no descendant of v is heavy, then v has a correct guess. When the criterion in Lemma 4.7 applies to a node v, we say that v has been counted. So, counted nodes are nodes that have been assigned a guess, which was then confirmed to be correct. Cuts and isles. Fix a view V of a history tree H. A set of nodes C in V is said to be a cut for a node v / ∈ C of V if two conditions hold: (i) for every leaf v of V that lies in the subtree hanging from v, the black path from v to v contains a node of C, and (ii) no proper subset of C satisfies condition (i). A cut for the root r whose nodes are all counted is said to be a counting cut (see Figure 2 , right). Let s be a counted node in V, and let F be a cut for v whose nodes are all counted. Then, the set of nodes spanned by the black paths from s to the nodes of F is called isle; s is the root of the isle, while each node in F is a leaf of the isle (see Figure 2 , right). The nodes in an isle other than the root and the leaves are called internal. An isle is said to be trivial if it has no internal nodes. If s is an isle's root and F is its set of leaves, we have a(s) ≥ v∈F a(v), because s may have some descendants in the history tree H that do not appear in the view V. If equality holds, then the isle is said to be complete; in this case, we can easily compute the anonymities of all the internal nodes by adding up anonymities starting from the nodes in F and working our way up to s. Algorithm overview. Our counting algorithm repeatedly assigns guesses to nodes based on known anonymities (starting from the nodes corresponding to the leader). Eventually some nodes become heavy, and the criterion in Lemma 4.7 causes the deepest of them to become counted. In turn, counted nodes eventually form isles; the internal nodes of complete isles are marked as counted, which gives rise to more guessers, and so on. In the end, if a counting cut has been created, a simple condition determines whether the anonymities of its nodes add up to the correct count, n. Algorithm details. The algorithm takes as input a view V (which, we recall, is the history of a process), and uses flags to mark nodes as "guessed" or "counted"; initially, no node is marked. Thanks to these flags, we can check if a node u ∈ V is a guesser: let u 1 , u 2 , . . . , u k be the children of u that are also in V (recall that a view does not contain all nodes of a history tree); u is a guesser if and only if it is marked as counted, all the u i 's are marked as counted, and a(u) = i a(u i ). The algorithm will ensure that nodes marked as guessed are well-spread at all times; if a level of V contains a guessed node, it is said to be locked. A level L t is guessable if it is not locked and has a non-counted node v that is guessable, i.e., there is a guesser u in L t−1 and the red edge {v, u} is present in V with positive multiplicity. The counting algorithm is as follows: Step 1. Assign anonymity 1 to all nodes corresponding to the leader, and mark them as counted. Step 2. If there are no guessable levels, go to Step 6. Otherwise, let v be a guessable non-counted node of smallest depth. Assign v a guess g(v) as in Equation (1), and mark v as guessed. Step 3. Scan the black path from v to r, incrementing the weight of the guessed nodes encountered. If along the way a heavy node v is created, immediately go to Step 4; otherwise, go to Step 2. Step 4. Assign the anonymity a(v ) = g(v ) to v , and mark it as counted (and no longer guessed). If v has now become the root or a leaf of a complete isle I, go to Step 5; otherwise, go to Step 2. Step 5. Compute the anonymities of all the internal nodes of the isle I, and mark them as counted. If some of them are guessed, unmark them and update all weights accordingly. Go to Step 2. Step 6. If there are no counting cuts, output "Unknown" without entering a terminal state. Otherwise, let C be a counting cut such that the deepest node v * ∈ C has minimum depth among all counting cuts. Let L t v * , let n = v∈C a(v), and let t be the current round (note that t can be inferred from the height of V). If t ≥ t + n , output the anonymities of the nodes in L 0 and terminate; otherwise, output "Unknown" without entering a terminal state. Invariants. We argue that the above algorithm maintains some invariants, i.e., conditions that are satisfied every time Step 2 is reached. Namely, (i) the nodes marked as guessed are well spread, (ii) there are no heavy nodes, and (iii) all complete isles are trivial. These can be verified by induction: (i) the algorithm never makes a guess in a locked level; (ii) as soon as a new guess in Step 2 creates some heavy nodes, the deepest one becomes counted, making all other nodes non-heavy (in Step 5, weights may only decrease, and no heavy nodes are created); (iii) as soon as a complete isle I is created due to a node v being marked as counted in Step 4, it is immediately reduced to a set of trivial isles. The invariants also imply that Steps 3 and 4 are correct: if no nodes are heavy to begin with, the new guessed node v may create heavy nodes only on the black path from v to r. Thus, the first heavy node along this path has a correct guess due to Lemma 4.7. Furthermore, since the anonymities assigned in Step 4 are correct, then so are the ones assigned in Step 5. Terminating condition. We will now prove that Step 6 is correct: that is, the algorithm indeed gives the correct output if the terminating condition is met. We already know that the anonymities computed for the nodes of the counting cut C are correct, and hence we only have to prove that the set P of processes represented by the nodes of C includes all processes. Assume the contrary; Lemma 4.2 implies that, if t ≥ t + |P | = t + n , there is a node z ∈ L t representing some process not in P . Thus, the black path from z to the root r does not contain any node of C, contradicting the fact that C is a counting cut whose deepest node is in L t . So, the terminating condition is correct. Running time. We have proved that the algorithm is correct; we will now study its running time. Proof. We will prove that, if the subtree hanging from a vertex v of V contains more than a(v) guessed nodes, then it contains a guessed node v such that w(v ) > a(v ). The proof is by wellfounded induction based on the subtree relation in V. If v is guessed, then we can take v = v. Otherwise, by the pigeonhole principle, v has at least one child u whose hanging subtree contains at least a(u) guessed nodes. Thus, v is found in this subtree by the induction hypothesis. Assume for a contradiction that at least n levels of V are locked; hence, V contains at least n guessed nodes. None of the nodes representing the leader is ever guessed, because all of them are marked as counted in Step 1. Hence, all of the guessed nodes must be in the subtrees hanging from the nodes in L 0 representing non-leader nodes, whose total anonymity is n − 1. Thus, by the pigeonhole principle, the subtree of one such node v ∈ L 0 contains more than a(v) guessed nodes. The node v must be in V, and therefore the subtree hanging from v contains a guessed node v such that w(v ) > a(v ). Since the algorithm's invariant (i) holds, we can apply Lemma 4.6 to v , which implies that there exist heavy nodes. In turn, this contradicts invariant (ii). We conclude that at most n − 1 levels are locked. Lemma 4.9 . Assume that all the levels of the history tree up to L t are entirely contained in the view V. Then, whenever Step 2 is reached and a counting cut has not been created yet, there are at most n − 2 levels in the range from L 1 to L t that lack a guessable non-counted node. Proof. Step 1 creates guessers in every level from L 0 to L t−1 (these are the nodes representing the leader); hence, these levels must have a non-empty set of guessers at all times. Consider a level L i with 1 ≤ i ≤ t, and assume that all the guessable nodes in L i are already counted. Let S be the set of guessers in L i−1 ; note that not all nodes in L i−1 are guessers, or else they would give rise to a counting cut. The network is 1-interval-connected, so there is a red edge {u, v} (with positive multiplicity) such that u ∈ S and the parent of v is not in S. By definition, the node v is guessable; therefore, it is counted. Also, since the parent of v is not a guesser, v must have a non-counted parent or a non-counted sibling; note that such a non-counted node is in V. We have proved that every level (up to L t ) lacking a guessable non-counted node contains a counted node v having a parent or a sibling that is not counted: we call such a node v a bad node. To conclude the proof, it suffices to show that there are at most n − 2 bad nodes up to L t . We will prove by induction that, if a subtree W of V contains the root r, no counting cuts, and no non-trivial isles, then W contains at most f − 1 bad nodes, where f is the number of leaves of W not representing the leader. The base case is f = 1, which holds because any counted non-leader node in W gives rise to a counting cut. For the induction step, let v be a bad node of maximum depth in W. Let (v 1 , v 2 , . . . , v k ) be the black path from v 1 = v to the root v k = r, and let 1 < i ≤ k be the smallest index such that v i is a branching node (i must exist, because v k branches into leader and non-leader nodes). Let W be the tree obtained by deleting the black edge {v i−1 , v i } from W, as well as the subtree hanging from it. Notice that the induction hypothesis applies to W : since v 1 is counted, and none of the nodes v 2 , . . . , v i−1 are branching, the removal of {v i−1 , v i } does not create counting cuts or non-trivial isles. Also, v 2 is not counted (unless perhaps v 2 = v i ), because v 1 is bad. Furthermore, none of the nodes v 3 , . . . , v i−1 is counted, or else v 2 would be an internal node of a (non-trivial) isle. Therefore, W has exactly one less bad node than W and at least one less leaf; the induction hypothesis now implies that W contains at most f − 1 bad nodes. Observe that the subtree V of V formed by all levels up to L t satisfies all of the above conditions, as it contains the root r and has no counting cuts, because a counting cut for V would be a counting cut for V, as well. Also, invariant (iii) ensures that V contains no non-trivial complete isles. However, since the levels up to L t are contained in V , all isles in V are complete, and thus must be trivial. We conclude that, if V has f non-leader leaves, it contains at most f − 1 bad nodes. Since the non-leader leaves of V induce a partition of the n − 1 non-leader processes, we have f ≤ n − 1, implying that the number of bad nodes up to L t is at most n − 2. Theorem 4.10. There is an algorithm that solves the Generalized Counting problem in 1-intervalconnected anonymous dynamic networks with a leader and terminates in at most 3n − 2 rounds. Proof. It suffices to prove that, if a process p executes the above algorithm at round t = 3n − 2, it terminates. By Corollary 4.3, the levels of the history tree up to L 2n−1 completely appear in p's history. Due to Lemmas 4.8 and 4.9, as long as a counting cut has not been created, at least one level between L 1 and L 2n−2 is guessable (because at most n − 1 levels are locked and at most n − 2 levels lack a guessable non-counted node). Hence, when Step 6 is reached, a counting cut C has been found whose deepest node is in L t , with t ≤ 2n − 2. The level L t is completely contained in p's history, and therefore n = v∈C a(v) = n. Thus, t = 3n − 2 ≥ t + n , and p terminates. Our analysis of the algorithm is tight: In Appendix C.2, we will show that there are 1-intervalconnected networks where the algorithm terminates in exactly 3n − 3 rounds. Unsolvable Problems. We will now prove that the multi-aggregation problems introduced in Section 2 are the only problems that can be solved deterministically in anonymous networks. Theorem 5.1. No problem other than the multi-aggregation problems can be solved deterministically, even when restricted to simple connected static networks with a unique leader. Proof. Let us consider the (static) network whose topology at round t is the complete graph G t = K n , i.e., each process receives messages from all other processes at every round. We can prove by induction that all nodes of the history tree other than the root have exactly one child. This is because any two processes with the same input always receive equal multisets of messages, and are therefore always indistinguishable. Thus, the history tree is completely determined by the multiset µ of all processes' inputs; moreover, a process' history at any given round only depends on the process' own input and on µ. By Theorem 3.1, this is enough to conclude that if a process' output stabilizes, that output must be a function of the process' own input and of µ, which is the defining condition of a multi-aggregation problem. Lower Bound. We now prove a lower bound of roughly 2n rounds on the Counting problem. In Appendix C.3, we will provide additional (albeit weaker) lower bounds for several other problems. We first introduce a family of 1-interval-connected dynamic networks. For any n ≥ 1, we consider the dynamic network G n whose topology at round t is the graph G (n) t defined on the system {p 1 , p 2 , . . . , p n } as follows. If t ≥ n − 2, then G (n) t is the path graph P n spanning all processes p 1 , p 2 , . . . , p n in order. If 1 ≤ t ≤ n − 3, then G (n) t is P n with the addition of the single edge {p t+1 , p n }. We assume p 1 to be the leader and all other processes to have the same input. Theorem 5.2. No deterministic algorithm can solve the Counting problem in less than 2n − 6 rounds, even in a simple 1-interval-connected dynamic network, and even if there is a unique leader in the system. If termination is required, the bound improves to 2n − 4. 2 Proof. Let us consider the network G n as defined above. It is straightforward to prove by induction that, at round t ≤ n − 3, the process p t+1 gets disambiguated, while all processes p t+2 , p t+3 , . . . , p n are still indistinguishable. So, the history tree of G n has a very regular structure, which is illustrated in Figures 3 and 4 . By comparing the history trees of G n and G n+1 , we see that the leaders of the two systems have identical histories from round 1 up to round 2n − 5. Thus, by Theorem 3.1, both leaders must have equal internal states and give equal outputs up to round 2n − 5. It follows that, if the leader of G n were to output the number n and terminate in less than 2n − 4 rounds, then the leader of G n+1 would do the same, producing the incorrect output n instead of n + 1. Assume now that the leaders of G n and G n+1 could stabilize on the correct output in less than f (n) = 2n − 6 and f (n + 1) = 2(n + 1) − 6 = 2n − 4 rounds, respectively. Then, at round 2n − 5, the two leaders would output n and n + 1 respectively, contradicting the fact that they should give the same output. Acknowledgments. The authors would like to thank Gregory Schwartzman for useful comments. We have presented an algorithm for the Generalized Counting problem that terminates in 3n − 3 rounds, which allows the linear-time computation of all deterministically computable functions in 1-interval-connected anonymous dynamic networks with a leader. We also proved a lower bound of roughly 2n rounds for the Counting problem, both for terminating and for stabilizing algorithms, and we gave a stabilizing algorithm for Generalized Counting that matches the lower bound (up to a small additive constant). Determining whether the 2n lower bound is tight for terminating algorithms is left as an open problem. We introduced the novel concept of history tree as our main investigation technique. History trees are a powerful tool that completely and naturally captures the concept of symmetry in anonymous dynamic networks. We have demonstrated the effectiveness of our methods by optimally solving a wide class of fundamental problems, and we argue that our technique can be used in similar settings, such as the case with multiple leaders, as well as to obtain better bounds for networks with special topologies or randomly generated networks. Figure 3 : The first rounds of the dynamic network G n used in Theorem 5.2 (left) and the corresponding levels of its history tree (right), where n = 6; the process in blue is the leader. The white nodes and the dashed edges in the history tree are not in the history of the leader at round 7. The labels p 1 , . . . , p 6 have been added for the reader's convenience, and mark the processes that get disambiguated, as well as their corresponding nodes of the history tree, which have anonymity 1. Figure 4 : The first rounds of the dynamic network G n+1 with n = 6. Observe that the history of the leader at round 7 is identical to the history highlighted in Figure 3 . The intuitive reason is that, from round 1 to round n − 3, both networks have a cycle whose processes are all indistinguishable (and are therefore represented by a single node in the history tree), except for the one process with degree 3. Thus, the history trees of G n and G n+1 are identical up to level n − 3. After that, the two networks get disambiguated, but this information takes another n − 3 rounds to reach the leader. Therefore, if the leader of G n and the leader of G n+1 execute the same algorithm, they must have the same internal state up to round 2n − 5, due to Theorem 3.1. In particular, they cannot give different outputs up to that round, which leads to our lower bounds on stabilization and termination for the Counting problem. A multiset on an underlying set X is a function µ : X → N. The non-negative integer µ(x) is the multiplicity of x ∈ X, and specifies how many copies of each element of X are in the multiset. The set of all multisets on the underlying set X is denoted as M X . A dynamic network is an infinite sequence G = (G i ) i≥1 , where G i = (V, E i ) is an undirected multigraph, i.e., E i is a multiset of unordered pairs of elements of V . In this context, the set V = {1, 2, . . . , n} is called system, and its n ≥ 1 elements are the processes. The elements of the multiset E i are called links; note that we allow any number of "parallel links" between two processes. 3 The standard model of computation for systems of processes specifies the following computation parameters: • three sets I, O, S, representing the possible inputs, outputs, and internal states for a process, respectively; • A partition of S into two subsets S T and S N , representing the terminal and non-terminal states, respectively; • an input map ι : I → S, where ι(x) represents the initial state of a process whose input is x; • an output map ω : S T → O, where ω(s) represents the output of a process in a terminal state s; • a function A : S N × M S → S, representing a deterministic algorithm for local computations. The algorithm takes as input the (non-terminal) state of a process p, as well as the multiset of states of all processes linked to p, and it outputs the new state for p. Given the above parameters and a dynamic network G = (G i ) i≥1 , the computation proceeds as follows. The system V is assigned an input in the form of a function λ : V → I. Time is discretized into units called rounds r 1 , r 2 , r 3 , etc.; the multigraph G i describes the links that are present at round r i , and is called the topology of the network at round r i . Each process in the system updates its own state at the end of every round. We denote by σ i (p) ∈ S the state of process p ∈ V after round r i , for i ≥ 1. Moreover, we define the initial state of p as σ 0 (p) = ι(λ(p)) (we could say that each process is assigned its initial state at "round r 0 "). During round r i , each process p ∈ V broadcasts its state to all its neighbors in G i ; then, p receives the multiset M i (p) of states of all its neighbors (one state per incident link in E i ). 4 Finally, if p's state is non-terminal, it computes its next state based on its current state and M i (p). In Note that processes are anonymous: they are initially identical and indistinguishable except for their input, and they all update their internal states by executing the same deterministic algorithm A. Once all processes in V are in a terminal state, the system's output is defined as the function ζ : V → O such that ζ(p) = ω(σ t (p)). If this happens for the first time after round r t , we say that the execution terminates in t rounds. Given an input set I and an output set O, a problem on (I, O) is a sequence of functions P = (π n ) n≥1 , where π n maps every function λ : {1, 2, . . . , n} → I to a function ζ : {1, 2, . . . , n} → O. Essentially, a problem prescribes a relationship between inputs and outputs: whenever a system of n processes is assigned a certain input λ, it must eventually terminate with the output ζ = π n (λ). We denote the set of all problems on (I, O) as P(I, O). We say that a problem P = (π n ) n≥1 ∈ P(I, O) is solvable in f (n) rounds if there exists computation parameters (i.e., an algorithm A, as well as a set of states S = S N ∪ S T , an input map ι, and an output map ω) such that, whenever a system V = {1, 2, . . . , n} of n processes is given an input λ : V → I and carries out its computation on a dynamic network G as described above, it terminates in at most f (n) rounds and outputs π n (λ), regardless of the topology of G. Note that the algorithm A must be the same for every n, i.e., it is uniform; in other words, the system is unaware of its own size. A weaker notion of solvability involves stabilization instead of termination. Here, the processes are only required to output π n (λ) starting at round f (n) and at all subsequent rounds, without necessarily reaching a terminal state. Since only trivial problems can be solved if no restrictions are made on the topology of the dynamic network G (think of a dynamic network with no links at all), it is customary to require that the dynamic network be 1-interval-connected. That is, if G = (G i ) i≥1 , we assume that G i is a connected multigraph for all i ≥ 1. Another assumption that is often made about the system is the presence of a unique leader among the processes. That is, the input set I is of the form I = {L, N } × I , and an input assignment λ : V → I is valid if and only if there is exactly one process p ∈ V , the leader, such that λ(p) = (L, x) for some x ∈ I (thus, all non-leader processes have an input of the form (N, x)). In this section we will define an important class of problems in P(I, O), the multi-aggregation problems. As we will see, these are precisely the problems that can be solved in 1-interval-connected anonymous dynamic networks with a unique leader. Given a system V and an input assignment λ : V → I, we define the inventory of λ as the function µ λ : I → N which counts the processes that are assigned each given input. Formally, µ λ is the multiset on I such that µ λ (x) = |λ −1 (x)| for all x ∈ I. A problem P ∈ P(I, O) is said to be a multi-aggregation problem if the output to be computed by each process only depends on the process' own input and the inventory of all processes' inputs. Formally, P = (π n ) n≥1 is a multi-aggregation problem if there is a function ψ : I × M I → O, called signature function, such that every input assignment λ : {1, 2, . . . , n} → I is mapped by π n to the output ζ : {1, 2, . . . , n} → O where ζ(p) = ψ(λ(p), µ λ ). If the signature function ψ(x, µ) of a multi-aggregation problem P ∈ P(I, O) does not depend on the argument x, then P is simply said to be an aggregation problem. Thus, all aggregation problems are consensus problems, where all processes must terminate with the same output. Notable examples of aggregation problems in P(R, R) include computing statistical functions on the input values, such as sum, average, maximum, median, mode, variance, etc. The Counting Problem C I is the aggregation problem in P(I, M I ) whose signature function is ψ(x, µ) = µ. That is, all processes must determine the inventory of their input assignment λ, i.e., count the number of processes that have each input. If all inputs are the same (or, in the presence of a leader, if I = {L, N }), the Counting Problem reduces to determining the total number of processes in the system, n. The Counting Problem is complete for the class of multi-aggregation problems, in the sense that solving it efficiently implies solving any other multi-aggregation problem efficiently (actually, with no overhead at all). The following theorem makes this observation precise. Proof. The proof is essentially the same whether the requirement is termination or stabilization. For brevity, we only discuss termination. Let A be an algorithm that solves C I in f (n) rounds with the computation parameters S = S N ∪ S T , ι, ω as defined in Appendix A.1. We will show how to solve P by modifying A and the above parameters. The idea is that each process should execute A while remembering its own input x. Once it has computed the inventory µ λ of the system's input assignment, it immediately uses x and µ λ to compute the signature function of P . We define the set of internal states for P as S = S × I, with non-terminal states S N = S N × I. The new input map is ι (x) = (ι(x), x) ∈ S for all x ∈ I. The algorithm A : S N × M S → S is defined as A ((s, x), µ) = (A(s, µ ), x), where µ is defined as µ : S → N such that S s → x∈I µ((s, x)). Finally, we define the output map as ω ((s, x)) = ψ(x, ω(s)), where ψ : I × M I → O is the signature function of P . Since A solves the Counting Problem, when a system V of n processes is assigned an input λ and executes A on a network G, within f (n) rounds each process p ∈ V reaches a terminal state s ∈ S T such that ω(s) = µ λ . Therefore, if the system executes A on the same input and in the same network, the process p reaches the terminal state (s, λ(p)) ∈ S in the same number of rounds. Thus, p gives the output ω ((s, λ(p))) = ψ(λ(p), ω(s)) = ψ(λ(p), µ λ ), as required by the problem P . We remark that Theorem A.1 makes no assumption on the dynamic network's topology or the presence of a leader. A history tree on an input set I is a quintuplet H = (H, u, B, R, ) such that: 6 • H is a countably infinite set of nodes, with u ∈ H; • (H, B) is an infinite undirected tree rooted at u, where every node has at least one child; • (H, R) is an infinite undirected multigraph, where all edges have finite multiplicities; • : H \ {u} → I is a function that assigns a label (h) ∈ I to each node h ∈ H other than u. The elements of B are called black edges, and (H, B) is the black tree of H. Similarly, (H, R) is the red multigraph of H, and its edges (with positive multiplicity) are called red edges. The depth of h ∈ H is the distance between the nodes u and h as measured in the black tree. For all i ≥ −1, we define the ith level L i ⊆ H as the set of nodes that have depth i + 1. Thus, The nodes of a history tree inherit their "parent-child-sibling" relationships from the black tree: for example, u is the parent of all the nodes in L 0 because it is connected to all of them by black edges; thus, every two nodes in L 0 are siblings, etc. A descending path in a history tree is a sequence of k ≥ 1 nodes (h 1 , h 2 , . . . , h k ) such that, for all 1 ≤ i < k, the unordered pair {h i , h i+1 } is either a black or a red edge and, if h i ∈ L j , then h i+1 ∈ L j with j > j. Equivalently, we say that (h k , h k−1 , . . . , h 1 ) is an ascending path. The node h 1 is the upper endpoint of the path, and h k is the lower endpoint. If k = 1, then h 1 is both the upper and the lower endpoint. Let h be a node in a history tree H = (H, u, B, R, ), and let H h ⊂ H be the set of all upper endpoints of ascending paths whose lower endpoint is h. The view of h in H, denoted as ν(h), is the (finite) subtree of H induced by H h . Namely, ν(h) = (H h , B h , R h , h ), where B h ⊂ B is the set of black edges whose endpoints are both in H h , R h is the restriction of R to the unordered pairs of nodes in H h , and h is the restriction of to H h . The node h is said to be the viewpoint of the view ν(h); note that the viewpoint is the unique deepest node in the view. We will denote by V I the set of all views of all history trees on the input set I. Given a dynamic network G = (G i = (V, E i )) i≥1 and an input assignment λ : V → I, we will show how to construct a history tree H = (H, u, B, R, ) with labels in I that is naturally associated with G and λ. At the same time, for all i ≥ −1, we will construct a representation function is a set of processes that, based on their "history", are necessarily "indistinguishable" at the end of round r i (we will also give a meaning to this sentence when i = −1 and i = 0). The anonymity of a node h ∈ L i ⊂ H is the number of processes that h represents, and is given by the function α : H → N + , where α(h) = |ρ −1 i (h)|. In this paradigm, the label (h) of a node h = u is the input λ(p) that each process p represented by h has received at the beginning of the execution (all such processes must have received the same input, or else they would have different histories, and they would not be necessarily indistinguishable). The black tree keeps track of the progressive "disambiguation" of processes: if two processes are represented by the same node h ∈ L i−1 , they have had the same history up to round r i−1 . However, if they receive different multisets of messages at round r i , they are no longer necessarily indistinguishable, and will therefore be represented by two different nodes in L i , each of which is a child of h in H. Red edges represent "observations": if, at round r i , each of the processes represented by node h ∈ L i has received messages from processes represented by node h ∈ L i−1 through a total of m links in G i , then R contains the red edge {h, h } with multiplicity m. We inductively construct the history tree H and the representation functions ρ i level by level. First we define ρ −1 (p) = u for all p ∈ V , where u is the root of H. The intuitive meaning is that, before processes are assigned inputs (i.e., at "round r −1 "), they are all indistinguishable, because the network is anonymous. Thus, the anonymity of the root node u is |V | = n. The level L 0 of H represents the system at the end of "round r 0 ", i.e., after every process p ∈ V has been assigned its input λ(p) ∈ I and has acquired an initial state ι(λ(p)). At this point, processes with the same input are necessarily indistinguishable. Thus, for every input x ∈ λ(V ), there is a node h x ∈ L 0 with label (h x ) = x. Accordingly, for every process p ∈ λ −1 (x), we define ρ 0 (p) = h x . In order to inductively construct the level L i of H for i ≥ 1, we define the concept of observation multiset i (p) ∈ M L i−1 of a process p ∈ V at round r i . This corresponds to the multiset of "necessarily indistinguishable" messages received by p at round r i , and its underlying set is L i−1 , i.e., the collection of equivalence classes of processes that are necessarily indistinguishable after round r i−1 . The definition of i (p) is similar to the definition of M i (p) in Appendix A.1, as these are two closely related concepts: Now, the children of h ∈ L i−1 in L i are constructed as follows. Define the equivalence relation ∼ h on the set of processes V h = ρ −1 i−1 (h) such that p ∼ h q if and only if i (p) = i (q). Let W 1 , W 2 , . . . , W k be the equivalence classes of ∼ h , with W 1 ∪ W 2 ∪ · · · ∪ W k = V h . The node h has exactly k children h 1 , h 2 , . . . h k in L i , one for each equivalence class of ∼ h . Thus, for every 1 ≤ j ≤ k and every process p ∈ W j , we define ρ i (p) = h j . Also, since W j ⊆ V h and a process' input never changes, we set (h j ) = (h). The red edges connecting h j with nodes in L i−1 match the observation multiset of the processes in W j . That is, if the node h ∈ L i−1 has multiplicity m in i (p), where p ∈ W j , then the red edge {h j , h } has multiplicity m in R. The following properties of history trees are easily derived from the definitions in Appendix B.2. Observation B.1. • No two nodes in L 0 have the same label, and each node in H \ (L −1 ∪ L 0 ) has the same label as its parent. • Edges only connect nodes in adjacent levels; if {h, h } is a black or red edge with h ∈ L i , then h ∈ L i−1 ∪ L i+1 . • If h ∈ L i with i ≥ −1 and h 1 , h 2 , . . . , h k ∈ L i+1 are the children of h, then We will now give a concrete meaning to the idea that the processes represented by a node of a history tree are "necessarily indistinguishable". That is, if a node is in the ith level, then all the processes it represents must have the same state at the end of round r i , regardless of the deterministic algorithm being executed (cf. Corollary B.3). We will first prove a fundamental result: the internal state σ i (p) of any process p ∈ V at the end of any round r i , with i ≥ 0, can be inferred from the process' history ξ i (p), which is defined as the view of the node of L i representing p, i.e., ξ i (p) = ν(ρ i (p)). Theorem B.2. Given any set of computation parameters (as defined in Appendix A.1), there exists a function F : V I → S such that, for every history tree H associated with a dynamic network G and an input assignment λ (as defined in Appendix B.2), and for every process p ∈ V and every i ≥ 0, F(ξ i (p)) = σ i (p). Proof. Let h = ρ i (p), and let ξ i (p) = ν(h) = (H h , B h , R h , h ) be the view of h in the history tree H = (H, u, B, R, ). We will define F (in terms of the computation parameters ι : I → S and A : S N × M S → S) in such a way that F(ξ i (p)) = F(ν(h)) = σ i (p). Note that F can identify h as the deepest node of ξ i (p). Also, it can compute i as the depth of h in the black tree (H h , B h ) minus 1. Hence, h and i do not have to be explicitly provided as arguments to F. The construction of F is done by induction on i. If i = 0, the view ξ 0 (p) = ν(h) contains the node h ∈ L 0 , whose label h (h) = (h) is the input of p, i.e., λ(p) (cf. the construction of L 0 in Appendix B.2). Therefore, we set F(ξ i (p)) = ι( (h)); indeed, F(ξ i (p)) = ι(λ(p)) = σ 0 (p) (cf. the definition of σ 0 (p) in Appendix A.1). Now let i ≥ 1, and assume that F(ξ i−1 (q)) has been defined for every q ∈ V . We will show how, given ξ i (p) = ν(h), the function F can compute σ i (p). By definition of view, it immediately follows that the view of any node h ∈ H h is contained in the view of h. That is, all nodes and all black and red edges of ν(h ) are contained in ν(h), and the two views also agree on the labels. Thus, given the history ξ i (p) = ν(h), the function F can infer the view of any node h ∈ H h by taking all the ascending paths in ν(h) with lower endpoint h . In particular, if {h, h } is a black or red edge in ν(h), then h ∈ L i−1 , and therefore F can determine the state σ i−1 (q) of any process q ∈ ρ −1 i−1 (h ), by the inductive hypothesis. Observe that the only black edge {h, h } ∈ B h incident to h connects it with its parent h ∈ L i−1 , and p ∈ ρ −1 i−1 (h ), due to Observation B.1. Thus, F can identify the parent of h and determine σ i−1 (p). Similarly, the observation multiset i (p) can be inferred by taking the multiplicities of all red edges of the form {h, h } ∈ R h (cf. the construction of the red edges in Appendix B.2). Again, for each such h ∈ L i−1 , it is possible to determine the state σ i−1 (q) of any process q ∈ ρ −1 i−1 (h ). The multiset of these states (with the multiplicities inherited from i (p)) is precisely M i (p), i.e., the multiset of states that p receives at round r i (cf. the definition of M i (p) in Appendix A.1). We conclude that F can compute σ i (p) by first determining σ i−1 (p) and M i (p), and then computing A(σ i−1 (p), M i (p)) (cf. the definition of σ i (p) in Appendix A.1). Corollary B.3. During a computation in an anonymous dynamic network, at the end of round r i , with i ≥ 0, all processes represented by the same node (in the ith level) of the history tree have the same state. Proof. The history at round r i of all processes represented by the node h ∈ L i is ν(h). Therefore, all such processes must have the same state F(ν(h)), by Theorem B.2. We will now describe the algorithm A * mentioned at the end of Section 3. This algorithm takes as input a process p's history at the end of the previous round ξ i−1 (p), as well as the multiset of histories of neighboring processes M i (p), and constructs the new history ξ i (p) by merging ξ i−1 (p) with all the histories in M i (p). Let us give a preliminary definition. A homomorphism from a view ν(a) = (H a , B a , R a , a ) ∈ V I to a view ν( The new history ξ i (p) can be constructed from ξ i−1 (p) and M i (p) as follows. The first step is to identify the viewpoint of ξ i−1 (p), which is the (unique) deepest node h in the view; note that h = ρ i (p). The second step is to "extend" ξ i−1 (p) by adding a new node h , with the same label as h, and the new black edge {h, h }. Let Z 0 ∈ V I be the resulting view; note that h is the (unique) child of h in Z 0 . Eventually, the node h will be the viewpoint of ξ i (p). Let ξ i−1 (q 1 ), ξ i−1 (q 2 ), . . . , ξ i−1 (q k ) be the histories with positive multiplicity in M i (p) (note that they must all be histories of processes at round r i−1 : such are the messages received by p at round r i ). The next phase of the algorithm is to construct a sequence of views Z 0 , Z 1 , Z 2 , . . . , Z k ∈ V I such that Z j is the smallest view in V I that contains both Z j−1 and ξ i−1 (q j ), for all 1 ≤ j ≤ k. In practice, the algorithm constructs Z j by starting from Z j−1 and gradually adding the "missing nodes" from ξ i−1 (q j ), at the same time constructing an (injective) homomorphism ϕ j from ξ i−1 (q j ) to Z j . First, the root of ξ i−1 (q j ) is mapped by ϕ j to the root of Z j−1 . Then, the algorithm scans all the nodes of ξ i−1 (q j ) level by level (i.e., doing a breadth-first traversal along the black edges). Let v be a node of ξ i−1 (q j ) encountered during the traversal, and let v be its parent in ξ i−1 (q j ). The algorithm attempts to match v with a child w of the node w = ϕ j (v ) in Z j−1 . The label of w should be the same as the label of v and, for every red edge {v, v } in ξ i−1 (q j ), connecting v with a previous-level node v , the edge {w, ϕ j (v )} should also appear in Z j−1 with the same multiplicity. If a node w with these properties does not exist, the algorithm creates one, and then sets ϕ j (v) = w. When the traversal is over, the resulting structure is Z j , by definition. Note that the final structure Z k coincides with ξ i (p), except for some missing red edges: these are the red edges incident to the viewpoint h which represent the messages received by p at round r i . Thus, for every 1 ≤ j ≤ k, the viewpoint h j of ξ i−1 (q j ) is found (as the unique deepest node in ξ i−1 (q j )) and the red edge {h , ϕ j (h j )} is added to Z k , with the same multiplicity as ξ i−1 (q j ) in M i (p). The resulting history is ξ i (p). The example in Figure 5 shows that the techniques in Section 4.1 are insufficient to formulate a correct terminating condition. The first level where all nodes are non-branching is L 0 , but the stabilizing algorithm Section 4.1 computes the wrong anonymities. The information on the actual size of the network can be kept hidden from the leader for an arbitrarily long time, which makes any naive terminating strategy ineffective. The example in Figure 6 , which can be easily generalized to networks of any size n, shows that the counting algorithm of Section 4.2 may terminate in 3n − 3 rounds. This almost matches our analysis in Theorem 4.10, which gives an upper bound of 3n − 2 rounds. Theorem C.1. No deterministic algorithm can solve the Counting Problem C I in an anonymous dynamic network of n processes in less than 1.5n − 2 rounds, even if the network is 1-intervalconnected, and even if there is a unique leader in the system. Proof. Let I = {L, N } × I be the input set, and let x ∈ I . Fix m ≥ 1, and let n = 2m and n = 2m + 1. Consider the two systems V = V n and V = V n with their respective dynamic networks G = G n,m = (G i = (V n , E i )) i≥1 and G = G n ,m = (G i = (V n , E i )) i≥1 (where G n,m and G n ,m are as defined above). We further define the input assignments λ : V → I and λ : V → I, which assign the input (L, x) to process 1 and the input (N, x) to all other processes. Thus, in both systems, process 1 is the leader, and all other processes are anonymous. We denote as H (respectively, H ) the history tree associated with λ and G (respectively, λ and G ), while ξ i (p) and ξ i (p ) denote the histories of processes p ∈ V and p ∈ V , respectively, at round r i . We define the d-neighborhood N i (p, d) of a process p ∈ V at round r i , with i ≥ 1, as the subgraph of G i induced by the processes that have distance at most d from p in G i (similarly, we define the d-neighborhood N i (p , d) of a process in p ∈ V ). We say that Recall that, for the first m − 1 rounds, the topology of both networks is a cycle graph. Thus, all processes at the same distance from their respective leader have equivalent (m − 1)-neighborhoods throughout the first m − 1 rounds, and therefore also have equal histories. That is, there is a function δ : V → V such that ξ i (p) = ξ i (δ(p)) for all p ∈ V and 1 ≤ i < m. Namely, δ(p) = p for all 1 ≤ p ≤ m, and δ(n − p) = n − p for all 0 ≤ p < m. Starting at round r m , the topology of both networks changes to a path graph with the leader at one endpoint. These path graphs have the property that the process at distance d from the leader in V has the same history as the process at distance d from the leader in V for all 0 ≤ d < n. Thus, the two leaders will keep having equal histories for the following n − 1 = 2m − 1 rounds. We conclude that the leaders of the two systems have equal histories up to round r 3m−2 . Assume for a contradiction that there are computation parameters (as defined in Appendix A.1) that cause all processes in both systems to output the inventory of their respective input assignments, µ λ and µ λ , thus solving C I , in less than 1.5n − 1 = 1.5n − 2 = 3m − 1 rounds. Since the leaders of V and V have equal histories throughout the first 3m − 2 rounds, by Theorem B.2 they must have equal states, as well. Thus, both leaders must give the same output upon termination, implying that µ λ = µ λ . This is a contradiction, because µ λ ((N, x)) = n − 1 = n = µ λ ((N, x)). We can extend Theorem C.1 to several other (multi-aggregation) problems. For example, fix n, k ∈ N + , let m = n/2 , and consider the two dynamic networks G = G n,m and G = G 2n+k−1,m for the systems V = V n and V = V 2n+k−1 , respectively. Let us assign a leader input to process 1 in both systems, any arbitrary k-tuple ((N, x 1 ), (N, x 2 ) , . . . , (N, x k )) of inputs to processes n + 1, n + 2, . . . , n + k in V , and another input (N, x) (not in the k-tuple) to all other processes. Now, the same argument used for proving Theorem C.1 shows that the two leaders have equal histories for the first 3m − 2 rounds. Thus, the leaders are not only unable to count the number of processes in less than 1.5n − 2 rounds, but are also unable to tell whether the system contains any process at all with inputs in the chosen k-tuple. Round 4+ Figure 8 : The dynamic network G n,m with m = 4 and n = 9, and its history tree. Observe that the leaders of this network and of the network in Figure 7 have isomorphic histories at round 3m − 2 = 10 (cf. Theorem C.1). case of interval-connected anonymous networks. We conclude the section by examining the average consensus problem, which is deeply related to counting. The problem of counting the size of a dynamic network has been first studied by the peer-to-peer systems community [33] . In this case having an exact count of the network at a given time is impossible, as processes may join or leave in an unrestricted way. Therefore, their algorithms mainly focus on providing estimates on the network size with some guarantees. The most related is the work that introduced 1-interval-connected networks [30] . They show a counting algorithm that terminates in at most n + 1 rounds when messages are unrestricted and in O(n 2 ) rounds when the message size is O(log n) bits. The techniques used heavily rely on the presence of unique IDs and cannot be extended to our settings. The study of computability on anonymous networks has been pioneered by Angluin in [1] and it has been a fruitful research topics for the last 30 years [1, 7, 13, 14, 15, 23, 41, 44] . A key concept in anonymous networks is the symmetry of the system; informally, it is the indistinguishability of nodes that have the same view of the network. As an example, in an anonymous static ring topology, all processes will have the exact same view of the system, and such a view does not change between rings of different size. Therefore, non-trivial computations including counting are impossible on rings, and some symmetry-breaking assumption is needed (such as a leader [23] ). The situation changes if we consider topologies that are asymmetric. As an example, on a wheel graph the central node has a view that is unique, and this allows for the election of a leader and the possibility, among other tasks, of counting the size of the network. Several tools have been developed to characterize what can be computed on a given network topology (examples are views [44] or fibrations [8] ). Unfortunately, these techniques are usable only in the static case and are not defined for highly dynamic systems like the ones studied in our work. Regarding the counting problem in anonymous static networks with a leader, [34] gives a counting algorithm that terminates in at most 2n rounds. The papers that studied counting in anonymous dynamic networks can be divided into two periods. A first series of works [12, 19, 20, 34] gave solutions for the counting problem assuming some initial knowledge on the possible degree of a processes. As a matter of fact [34] conjectured that some kind of knowledge was necessary to have a terminating counting algorithm. A second series of works [17, 24, 26, 27, 28] has first shown that counting was possible without such knowledge, and then has proposed increasingly faster solutions. We remark that all these papers assume that a leader (or multiple leaders in [27] ) is present. This assumption is needed to break the symmetry. in the network, calculates an upper bound U on the size of the network; this upper bound may be exponential in the actual network size (U ≤ d n ). Assuming the knowledge of an upper bound on the degree, [19] given a counting algorithm that computes n. Such an algorithm is really costly in terms of rounds; it has been shown in [12] to be doubly exponential in the network size. The algorithm proposes a mass distribution approach akin to local averaging [43] . An experimental evaluation of the algorithm in [19] can be found in [21] . The result of [19] has been improved in [12] , where, again assuming knowledge of an upper bound d on the maximum degree of a node, an algorithm is given that terminates in O(n(2d) n+1 log(n) log d ) rounds. A later paper [20] has shown that counting is possible when each process knows its degree before starting the round (for example, by means of an oracle). In this case, no prior global upper bound on the degree of processes is needed. [20] only show that the algorithm eventually terminates but does not bound the termination time. We remark that all the above works assume some knowledge on the dynamic network, as an upper bound on the possible degrees, or as a local oracle. Moreover, all of these works give exponential-time algorithms. Counting without knowledge on the degrees. The first work proposing an algorithm that does not require any knowledge of the network was [17] . The paper proposed an exponential-time algorithm that terminates in O(n n 4 ) rounds. Moreover, it also gives an asymptotically optimal algorithm for a particular category of networks (called persistent-distance). In this type of network, a node never changes its distance from the leader. This result was improved in [24, 26] , which presented a polynomial-time counting algorithm. The paper proposes Methodical Counting, an algorithm that counts in O(n 5 log 2 (n)) rounds. Similar to [19, 20] , the paper uses a mass-distribution process that is coupled with a refined analysis of convergence time and clever techniques to detect termination. The paper also notes that, using the same algorithm, all algebraic and boolean functions that depend on the initial number of processes in a given state can be computed. The authors of [24, 26] extended their result to work in networks where l ≥ 1 leaders are present (with l known in advance) in [28] . They create an algorithm that terminates in O( n 4+ l log 3 (n)) rounds, for any > 0. In particular, when l = 1, this results improves the running time of [24, 26] . Finally, in [27] , they show a counting algorithm parameterized by the isoperimetric number of the dynamic network. The technique used is similar to [24, 26] , and it uses the knowledge of the isoperimetric number to shorten the termination time. Specifically, for adversarial graphs (i.e., with non-random topology) with l leaders (l is assumed to be known in advance), they give an algorithm terminating in O( n 3+ li min 2 log 3 (n)) rounds, where i min is a known lower bound on the isoperimetric number of the network. This improves the work in [28] , but only in graphs where i min is ω( 1 √ n ). The authors also study various types of graphs with stochastic dynamism; we remark that in this case they always obtain superlinear results, as well. The best case is that of Erdős-Rényi, graphs where their algorithm terminates in O( n 1+ lp min 2 log 5 (n)) rounds; here p min is the smallest among the probabilities of creating an arc on all rounds. Specifically, if p min = O( 1 n ), their algorithm is at least cubic. Summarizing, to the best of our knowledge, no linear-time algorithm is known for anonymous dynamic networks, even when additional knowledge is provided (e.g., the isoperimetric number [27] ), or when the topology of the network is random and not worst-case. Notice that a random topology is a really powerful assumption in anonymous networks, as it is likely to greatly help in breaking symmetry. We stress that our algorithms run in linear time without requiring any prior knowledge, and works for worst-case dynamic topologies (and thus, also in the case of a random dynamicity). Lower bounds on counting. From [30] , a trivial lower bound of n − 1 rounds can be derived, as counting obviously requires information from each node to be spread in the network. Interestingly, prior to our work, little was known apart from this result. The only other lower bound is in [17] , which shows a specific category of anonymous dynamic networks with constant temporal diameter (the time needed to spread information from a node to all others is at most 3 rounds), but where counting requires Ω(log n) rounds. Therefore, our lower bound of roughly 2n rounds greatly improves on the previously known lower bounds for the general case (networks that have an arbitrary temporal diameter). Counting is deeply related to the average consensus problem. In this problem, each process v i starts with an input value x i (0), and processes must calculate the average of these initial values. Note that the Generalized Counting trivially leads to a solution for the average consensus. The first paper to propose a decentralized solution was [43] . It introduced an approach called "local averaging", where each process updates its local value x i (r) at every round r as follows: The value a ij (r) is taken from a weight matrix that can model a dynamic graph. The -convergence of this algorithm is defined as the time it takes to be sure that is larger than the discrepancy between the local value of each node and the mean (e.g., max i x i (r) − i∈V x i (0)/|V | ). The local averaging approach has been studied in depth, and several upper and lower bounds forconvergence are known for both static and dynamic networks [38, 39] . The procedure -converges in O(|V | 3 log( 1 )) rounds if, at every round, the weight matrix A(r)|(A(r)) ij = a(r) ij is doubly stochastic (i.e., the sum of the values on rows and columns is 1) [36] . In a dynamic network, it is possible to have doubly stochastic weight matrices when an upper bound on the node degree is known [16] . We remark that local averaging algorithms do not need unique IDs, and thus work in anonymous dynamic networks; we also note that the process does not explicitly terminate, but just converges to the average of the inputs. To the best of our knowledge, there is no solution to average consensus based on local averaging or other techniques with a linear convergence time. Our algorithm shows that solving the average consensus in 1-interval-connected dynamic anonymous network is possible in linear time with strict termination and perfect convergence ( = 0). Moreover, our lower bound on counting is also a lower bound on average consensus (if the leader starts with value of 1 and all the other processes with 0's, the average converges to the inverse of the size). Thus, our paper shows that a lower bound on convergence of any average consensus algorithm is roughly 2n in anonymous dynamic networks. Local and Global Properties in Networks of Processors (Extended Abstract) Fast Computation by Population Protocols with a Leader Time and Space Optimal Counting in Population Protocols Mind the GAP: Security & Privacy Risks of Contact Tracing Apps Space-Optimal Counting in Population Protocols A Self-stabilizing Transformer for Population Protocols with Covering An Effective Characterization of Computability in Anonymous Networks Fibrations of Graphs. Discrete Mathematics Shortest, Fastest, and Foremost Broadcast in Dynamic Networks Time-varying Graphs and Dynamic Networks Counting in Practical Anonymous Dynamic Networks Is Polynomial A Faster Exact-Counting Protocol for Anonymous Dynamic Networks Groupings and Pairings in Anonymous Networks Local Terminations and Distributed Computability in Anonymous Networks The Total s-Energy of a Multiagent System Brief Announcement: Investigating the Cost of Anonymity on Dynamic Networks Non Trivial Computations in Anonymous Dynamic Networks Conscious and Unconscious Counting on Anonymous Dynamic Networks Counting in Anonymous Dynamic Networks Under Worst-Case Adversary Counting in Anonymous Dynamic Networks: An Experimental Perspective Population Protocols with Faulty Interactions: The Impact of a Leader Assigning Labels in Unknown Anonymous Networks Polynomial Counting in Anonymous Dynamic Networks with Applications to Anonymous Dynamic Algebraic Computations Polynomial Anonymous Dynamic Distributed Computing Without a Unique Leader Polynomial Counting in Anonymous Dynamic Networks with Applications to Anonymous Dynamic Algebraic Computations Supervised Average Consensus in Anonymous Dynamic Networks Polynomial Anonymous Dynamic Distributed Computing Without a Unique Leader Gradient Clock Synchronization in Dynamic Networks. Theory of Computing Systems Distributed Computation in Dynamic Networks Coordinated Consensus in Dynamic Networks Dynamic Networks: Models and Algorithms Peer to Peer Size Estimation in Large and Dynamic Networks: A Comparative Study Naming and Counting in Anonymous Unknown Dynamic Networks Elements of the Theory of Dynamic Networks On Distributed Averaging Algorithms and Quantization Effects Information Dissemination in Highly Dynamic Graphs Convergence Speed in Distributed Consensus and Averaging A Lower Bound for Distributed Averaging Algorithms on the Line Graph Comparison of Initial Conditions for Distributed Algorithms on Anonymous Networks Randomness vs. Time in Anonymous Networks Use of Apps in the COVID-19 Response and the Loss of Privacy Protection Problems in Decentralized Decision Making and Computation Computing on an Anonymous Network Computing on Anonymous Networks. I. Characterizing the Solvable Cases We will show that a large class of multi-aggregation problems cannot be solved in an anonymous dynamic network in less than 1.5n − 2 rounds, even if the network's topology may change only once. Note that the bound of Theorem 5.2 is better, but it only applies to the Counting Problem, and requires the network's topology to change Ω(n) times.Our new lower bound is based on the construction of some 1-interval-connected dynamic networks whose topology changes from a cycle graph to a path graph (refer to Figures 7 and 8) . Given two parameters n, m ∈ N + with m < n, we define the system V n = {1, 2, . . . , n} and the dynamic network G n,m = (G i = (V n , E i )) i≥1 as follows. For all 1 ≤ i < m, the edge multiset E i contains all edges of the form (j, j + 1) with 1 ≤ j < n, as well as (1, n), all with multiplicity 1 (thus, G i is a cycle graph spanning all processes). For i ≥ m, the topology changes slightly: the edges (m, m + 1) and (1, n) are removed, and the edge (m, n) is introduced, with multiplicity 1 (thus, G i is a path graph spanning all processes, with endpoints 1 and m + 1).We will first apply our technique to the Counting Problem. Although this is redundant in light of Theorem 5.2, it allows us to showcase a proof pattern that applies to several more problems. We examine the related work on counting and related problems by first discussing the case of dynamic networks with unique IDs, then the case of static anonymous networks, and finally the