  A team consisting of an unknown number of mobile agents, starting from
different nodes of an unknown network, possibly at different times, have to
meet at the same node. Agents are anonymous (identical), execute the same
deterministic algorithm and move in synchronous rounds along links of the
network. Which configurations are gatherable and how to gather all of them
deterministically by the same algorithm?
  We give a complete solution of this gathering problem in arbitrary networks.
We characterize all gatherable configurations and give two universal
deterministic gathering algorithms, i.e., algorithms that gather all gatherable
configurations. The first algorithm works under the assumption that an upper
bound n on the size of the network is known. In this case our algorithm
guarantees gathering with detection, i.e., the existence of a round for any
gatherable configuration, such that all agents are at the same node and all
declare that gathering is accomplished. If no upper bound on the size of the
network is known, we show that a universal algorithm for gathering with
detection does not exist. Hence, for this harder scenario, we construct a
second universal gathering algorithm, which guarantees that, for any gatherable
configuration, all agents eventually get to one node and stop, although they
cannot tell if gathering is over. The time of the first algorithm is polynomial
in the upper bound n on the size of the network, and the time of the second
algorithm is polynomial in the (unknown) size itself.
  Our results have an important consequence for the leader election problem for
anonymous agents in arbitrary graphs. For anonymous agents in graphs, leader
election turns out to be equivalent to gathering with detection. Hence, as a
by-product, we obtain a complete solution of the leader election problem for
anonymous agents in arbitrary graphs.
