A Low-Latency and Energy-Efficient Neighbor Discovery Algorithm for Wireless Sensor Networks

Wireless sensor networks have been widely adopted, and neighbor discovery is an essential step to construct the networks. Most existing studies on neighbor discovery are designed on the assumption that either all nodes are fully connected or only two nodes compose the network. However, networks are partially connected in reality: some nodes are within radio range of each other, while others are not. Low latency and energy efficiency are two common goals, which become even more challenging to achieve at the same time in partially connected networks. We find that the collision caused by simultaneous transmissions is the main obstruction of achieving the two goals. In this paper, we present an efficient algorithm called Panacea to address these challenges by alleviating collisions. To begin with, we design Panacea-NCD (Panacea no collision detection) for nodes that do not have a collision detection mechanism. When n is large, we show the discovery latency is bounded by O(n·lnn) for any duty cycle (the percentage time to turn on the radio), where each node has n neighbors on average. For nodes that can detect collisions, we then present Panacea-WCD which also bounds the latency within O(n·lnn) slots. Finally, we conduct extensive evaluations and the results also corroborate our analyses.


Introduction
Wireless sensor networks have been widely adopted in a wide range of Internet-of-Things (IoT) applications such as smart cities [1], health-care systems [2,3], intelligent detection [4,5], and remote monitoring [6][7][8]. In general, a large number of sensor nodes would be dispatched or deployed in some monitoring area to collect or aggregate information for further intelligent decisions. With the fast development of sensor system and communication technology, these sensor nodes could be deployed in a distributed manner without any pre-defined network topology; they can compose a wireless network to exchange information with the help of advanced communication technologies, such as bluetooth, wifi, 5G, etc.
Neighbor discovery is a fundamental process of constructing the wireless network among the sensor nodes, where each sensor node could discover other sensors within its communication range. As a cornerstone and an essential step in configuring wireless sensor networks, neighbor discovery has been extensively studied in the past few years [9][10][11][12][13][14][15][16][17][18][19][20][21][22] and the main objective of these algorithms is to reduce the discovery latency for a specific node or the whole network.
The extant algorithms can be classified into two categories. The probabilistic methods exploit the probability theory to reduce the communication collision caused by multiple transmissions simultaneously. These methods could make sensor nodes discover the neighbors within an expected low latency, but they all assume the network is fully connected where any two nodes can communicate directly. However, a large number of sensor nodes would be deployed in a large area and these nodes cannot communicate directly when their distance is far away or some nodes are restricted due to extreme environment. The deterministic methods could guarantee the discovery process where the sensor nodes only turn on their radios for a short time, but these methods are applicable to two nodes since they do not consider the collisions that may exist among a large number of sensors. Hence, these methods cannot be adopted directly for a large number of sensors, as the collisions would affect the normal communication process.
In designing efficient neighbor discovery algorithms for wireless sensor networks in IoT applications, there are two main challenges. First of all, sensor nodes have limited battery since the size of the sensors is small and battery recharging would be costly in applications like agricultural monitoring or underwater detecting; the node could turn on its radio only for sufficient communication and keep the radio off to save energy. Second, some IoT applications need a large number of sensors that are distributed in a large area or in some hostile environment; the sensors can only compose a partially connected network in which some nodes are not within the radio range or some nodes can be detected with some probability due to the obstacle or the block in the environment. However, the extant works cannot solve the two challenges concurrently.
To save energy, sensor nodes switch their radios off for most of the time and only turn the radios on for necessary communication. The fraction of time a node turns its radio on is denoted as a duty cycle. Some existing algorithms transmit and listen with certain probabilities that are related to duty cycle [16,20,22], but they assume the network is fully connected, which is unrealistic in real IoT application. Some works focus on minimizing discovery latency [16,20], which is the time to discover all neighbors. However, they assume the nodes keep radios on all the time (duty cycle is 1) and these nodes would run out of energy quickly. Many deterministic protocols minimize discovery latency with a given duty cycle in [9,11,12,14,15,17,19]. Nevertheless, these methods only aim at two nodes, and they ignore the communication collisions among multiple nodes. By experiment, we find collisions caused by simultaneous transmissions result in a waste of time and energy. We considered a partially connected network with 1000 nodes and a probability of 0.5 for two nodes to be neighbors. We found that the collision slots of Hello [19], a deterministic protocol designed for two nodes, make up 99.8% of the time; while the collision slots of PND [18], a probabilistic protocol, make up 46.5% of the time. That means, because of collisions, existing works waste time and energy, and cannot achieve low latency and energy efficiency for the partially connected networks.
In this paper, we propose a low-latency and energy-efficient neighbor discovery algorithm called Panacea to address the above two challenges. Our algorithms take the sensors' duty cycle into consideration and adopt the collision detection mechanism to shorten the discovery latency. We summarize our contributions as follows: • We propose the Panacea algorithm for a partially connected network which discovers all neighbors in O(n ln n) slots where n is the number of neighbors on average; • With the collision detection hardware mechanism, we modify the algorithm, creating Panacea-WCD, which can alleviate the communication collisions; • Panacea is suitable for both synchronous (i.e., all nodes are activated at the same time) and asynchronous (i.e., all nodes are activated at different time slots) scenarios.
We have conducted extensive simulations to evaluate the proposed algorithm. The results show that Panacea improves both latency and energy efficiency. For both synchronous and asynchronous scenarios, we analyze that the discovery latency can be bounded within O(n ln n) slots theoretically, and the simulation results also corroborate the analysis. Compared with Coupon [20] and PND [18], Panacea reduces the discovery latency by 60% and 92%, respectively, for synchronous scenarios, while reduces the discovery latency by 30% and 90% for asynchronous scenarios. Panacea could save 40% energy when it achieves similar discovery latency with Coupon. In addition, Panacea shows its best performance in regards to the trade-off between discovery latency and duty cycle, compared with Coupon, PND, Aloha-like [22], and Hello [19].
The rest of this paper is organized as follows. We review existing approaches in Section 2 and introduce the preliminaries in Section 3. Then, we propose the Panacea algorithm and analyze the efficiency in Section 4. With the collision detection mechanism, we propose the Panacea-WCD algorithm in Section 5 and present how the collision can be utilized in the algorithm. We implement Panacea and illustrate the comparison results in Section 6. Finally, we conclude this paper in Section 7.

Related Work
In recent years, wireless sensor networks have been extensively studied [1,[3][4][5][6][7][8][23][24][25][26][27][28]; as a cornerstone of constructing wireless sensor networks, increasingly sophisticated protocols for neighbor discovery have been proposed. These neighbor-discovery protocols mainly fall into two categories. One category is the probabilistic methods, which is to exploit the probability theory to discover nodes within an expected time, statistically speaking. The other category is the deterministic methods, which is to utilize mathematical theorems to guarantee the discovery between two nodes.
In probabilistic algorithms, each node in the network transmits, listens, or sleeps with a certain probability at each time slot, and the sum of these three probabilities is 1. One of the traditional methods is Birthday protocols, seen in [16]. It utilizes random independent transmissions based on the birthday paradox (i.e., when there are 23 people, the probability that at least two have the same birthday exceeds 0.5), and saved a great deal of energy with a high expected proportion of discovered neighbors. This method was further studied as an Aloha-like algorithm in [20], based on the classical coupon collector's problem. This algorithm first introduced the reception feedback with a collision detection mechanism, and mathematically showed that discovery latency was bounded in both scenarios, when nodes in the network are with or without a collision detection mechanism. Later on, a detailed physical layer mechanism was proposed in [29] for how nodes in receive mode detect the channel status, and methods at higher layers were also described based on the reception status information at transmitters. However, these methods only focused on improving the proportion of discovered neighboring nodes, ignoring the significance of saving energy.
Following that, similar and nicer probabilistic algorithms with a pre-defined duty cycle were proposed to save energy in [18,22]. However, these two methods only considered unrealistic fully connected networks, where every two nodes in the network are ideally connected. Besides, sophisticated hardware tools were used to reach a good tradeoff between latency and duty cycle in [30], but it required a complicated internal mechanism and increased the network cost. Recently, more methods targeted at collision problems are proposed in [31][32][33][34], but they introduced overhead to assist for packet collision indication, which adds to the complexity of networks. In deterministic algorithms, radios are pre-scheduled to be "on" or "off" in each time slot based on some mathematical theorems to guarantee the discovery between every two neighbors. According to a survey in [35], three methods were usually adopted to guarantee the discovery, i.e., over-half occupation, quorum system, and co-prime. First, over-half occupation is to guarantee the overlap of active slots by keeping two nodes on for more than half of their slots. For example, given n slots in a period, if two nodes are active for at least (n+1) 2 slots, they must have some overlapping active slots. On the other hand, having more than half of the slots active means the energy usage is quite high. To reduce the excessive energy consumption, a more intelligent way is to divide a period into r cycles with k slots each cycle and allocate active slots in each cycle. This incentive was adopted in SearchLight [9]. Second, quorum system considers m 2 slots as an m × m slot matrix, where each node takes one row and one column slots as active. This idea, implemented in [11,14,15] ensures discovery due to the indispensable intersected active slots. Among these algorithms, only Hedis [11] supports asymmetric duty cycle. Third, co-prime takes advantage of the Chinese remainder theorem [36]. For example, methods like Disco [12], U-Connect [15], and Todis [11] guarantees the intersection of active slots by making nodes active at the product of preset numbers that are co-prime to one another. However, most of these deterministic algorithms are designed for two nodes, despite being applied to multi-node scenarios without devising any approaches to deal with collisions.
In a more realistic scenario, when nodes are in a large, partially-connected network, probabilistic algorithms have an edge over deterministic ones in terms of reducing the number of collisions. Given the duty cycle, we can adjust the probabilities of transmission and listening in each slot to alleviate collisions. Ideally, the goal of designing neighbor discovery protocols is to guarantee discovery within a reasonable amount of time while minimizing the number of active slots for each node to save energy.
There are also some other algorithms that are designed for wireless sensor networks. Neighbor discovery algorithms are proposed with mobile sink nodes in [37,38] and a low latency protocol called Welcome is presented in [39] for mobile IoT devices. Some heuristic algorithms are also proposed with mobile sink nodes to improve the discovery performance in [40,41]. However, these algorithms are inapplicable since we do not consider mobile nodes in this paper.

Preliminaries
In this section, we introduce the system model and formulate the neighbor discovery problem for wireless sensor networks formally.

Sensor Node Model
Assuming that there are N sensor nodes in total that are deployed for a specific IoT application; we denote them as set U = {u 1 , u 2 , . . . , u N }. Suppose each node u i has a unique identifier (ID) i. Time is assumed to be divided into slots of equal length t 0 , which is sufficient to complete communications. All nodes can communicate through a specific channel for information exchanging. Suppose there are three states for each node: {Transmit, Listen, Sleep}, where Transmit means a node u i broadcasts (sends packets) on the channel; Listen means node u i listens on the channel and it can receive packets (message) from neighbors; and Sleep means node u i turns its radio off and does nothing to save energy. In each slot, a node can choose to be in any state by turning on or off its radio. For simplicity, we assume state transitions do not consume any time or energy, and only nodes that are transmitting or listening consume their battery power.
Denote the activation time of node u i as t s i , which implies the node does not work and stays in sleep mode until t s i . It is called a synchronous scenario if all deployed nodes are activated at the same time, i.e., t s i = t s j , ∀u i , u j ∈ U; otherwise it is called an asynchronous scenario. For a sufficiently long time from t s i to T, denote the number of slots that node u i is in Transmit, Listen, or Sleep state as We define the duty cycle of the node as For a specific IoT application, the duty cycle is normally defined in advance. In some hostile environment, it is costly to recharge the battery and thus the duty cycle would be very small, while the value could be large for some amicable applications.

Network Model
Most probabilistic works [16,20] only consider a fully connected network, where any two nodes are neighbors and they compose a fully connected network; this assumption is unrealistic. In this paper, we study the neighbor discovery process in a partially connected network, where some nodes are not neighbors, i.e., they are not connected directly for communication. We introduce two different network representations.
Considering a hostile environment where two nodes are neighbors with some probability, we use neighboring matrix M N×N to represent the neighboring relations. If node u i is a neighbor of u j , we set M ij and M ji to be 1 (we assume the neighboring relation is undirected and u j is also a neighbor of u i ), else the value of the entrance is 0. We assume u i is a neighbor of u j with probability p n due to the obstacle or other blocking scenarios where p n ∈ (0, 1). Clearly, the network is a fully connected one when p n = 1. In this paper, we consider a partially connected network where p n < 1. Therefore, a node would have n = p n (N − 1) neighbors on average. For a large N, we can approximate n ≈ p n N when it does not affect the analyses.
Considering another scenario where the nodes are deployed in a large field and the distance between two nodes may exceed the maximum radio range, we denote the distance of node u i , u j as d(u i , u j ) and two nodes are called neighbors where ∆ is the maximum radio range two nodes can communicate. Then the network topology would be determined after the deployment of the sensor nodes. In this paper, we suppose the nodes are deployed by the uniform distribution in a large area D. If the area D is covered by a ∆ × ∆ rectangle, all nodes are located within their radio range and they compose a fully connected network. We assume a large area D that cannot be covered by such a rectangle and the nodes compose a partially connected network.

Collision Model
Generally speaking, when one node u i transmits through the channel, another node u j who listens on the channel simultaneously could receive the transmitted packet/message and decode the message successfully. However, if two or more nodes transmit concurrently on the channel, communication collision occurs and u j cannot decode the message correctly. Therefore, we assume a node u j can discover its neighbor u i only when u j listens on the channel while u i is u j 's only neighbor who transmits.
In some design, communication collisions can be detected by hardware mechanism [18,20]. As described above, there are two situations for an unsuccessful discovery. The first scenario is no neighbor transmits while the second scenario is more than one neighbor transmit simultaneously. With the collision detection (CD) mechanism, a listening node can distinguish whether collisions occur or no neighbors is transmitting, apart from successful discovery. This CD mechanism enables the listening node to notify its transmitting neighbors of the transmission outcomes, and hence we can use this mechanism to design efficient algorithm.

Problem Definition
Neighbor discovery is not bidirectional, which means u i discovering u j is not equal to u j discovering u i . We first define discovery latency between two nodes as follows. Definition 1. Discovery latency L(i, j) is defined as the duration from when the sensor node u i starts to when u i discovers its neighboring node u j .
Formally, suppose node u i listens in time slot T while its neighbor node u j transmits in slot T j (the only neighbor who transmits), we say u i discovers u j and the discovery latency can be computed as We define the discover problem for a specific node u i as follows.

Problem 1.
Considering an arbitrary node u i and the set of neighbors NS(u i ) = {u j |M ji = 1}, design the algorithm for each node in each slot such that u i can discover all nodes in NS(u i ).
We define the discovery latency of node u i as L(i), which represents the time to discover all neighbors: Since the sensor nodes may be activated in different time slots, we define the discovery latency of the network L M as the maximum discovery latency of all nodes: The objective is to design an efficient algorithm that can discover the neighbors in a short time (L M ) under the pre-defined duty cycle in a partially connected network. We list the notations in Table 1.
The discovery latency that node u i discovers node u j NS(u i ) The set of node u i 's neighboring nodes The discovery latency that node u i discovers all neighbors L M The discovery latency of the network

Panacea: An efficient Neighbor Discovery Algorithm
In this section, we describe Panacea, a low-latency, energy-efficient neighbor discovery algorithm for a partially connected network. To begin with, we assume the sensor nodes do not have a collision detection mechanism; we present the proposed Panacea algorithm and analyze the performance for both synchronous and asynchronous scenarios.

Algorithm Description
For any node u i , suppose it has n neighbors on average and the pre-defined duty cycle of the node is θ i . When the nodes cannot detect communication collision, we introduce the idea of designing the probabilistic algorithm called Panacea-NCD (Panacea no collision detection).
Without a collision detection mechanism, node u i transmits with probability p t i , listens with probability p l i , and sleeps with probability p s i in each time slot t. For each state, node u i takes the corresponding operations below.

•
If u i chooses state Transmit, it transmits a message containing its source ID on the channel; We describe the algorithm formally as Algorithm 1. Each node u i repeats the algorithm every time slot until it discovers all neighbors. In each time, node u i generates a random value r ∈ (0, 1) and takes corresponding actions when r ≤ p t i , p t i < r ≤ θ i , and r > θ i . The important part of the algorithm is to design the proper transmission probability p t i . It is obvious that p t i + p l i + p s i = 1. Due to different applications, each node's duty cycle is determined in advance and we denote it as θ i for node u i ; since the duty cycle denotes the fraction of time slots that u i is transmitting or listening, hence Considering that nodes are comparatively well-distributed in the network, we suppose the probabilities of each node in each state are the same for simplicity. That is, ∀i ∈ To minimize the probability of collisions, we derive an approximation of the optimal transmission probability that can alleviate communication collisions to help achieve low discovery latency: We will show the procedure of deriving the transmitting probability in the following parts. As described in the algorithm, node u i selects the Transmit state with probability p t i = 1 n (Line 4-5), selects the Listen state with probability θ i − p t i (Line 6-7), and selects the Sleep state with probability 1 − θ i (Line 8-9). We analyze how to determine the transmission probability and show the efficiency of the algorithm.
if r ≤ p t i then 5: node u i transmits on the channel 6: else if p t i < r ≤ θ i then 7: node u i listens 8: else 9: node u i sleeps 10: end if 11: end while

Algorithm Analysis of Synchronous Scenario
We first analyze the algorithm's efficiency of synchronous scenario where all nodes are activated simultaneously. We assume the network is represented by matrix M N×N and any two nodes u i , u j are neighbors with probability p n ∈ (0, 1). We first derive the algorithm's discovery latency and derive the transmitting probability that minimizes the latency; then we show the upper bound of the discovery latency that can be utilized as a termination condition.

Expectation Analysis of Discovery Latency
According to the Panacea-NCD algorithm, we can easily derive that the probability that node u i discovers a specific neighboring node u j successfully in a given slot is: This is because all nodes are activated at the same time and these nodes would select states independently. Node u i can discover u j only when u j selects the Transmit state with probability p t , node u i selects the Listen state with probability p l = θ − p t , while other n − 1 neighbors select the Sleep or Listen state with probability p l + p s = 1 − p t .
By maximizing p suc , we can alleviate the maximum amount of collisions. Thus, we derive the transmission probability p t that maximizes p suc with the derivative Substituting this into the formulation, the probability that node u i discovers a specific neighbor successfully in a given slot is p suc ≈ θ en . We approximate these equations when n is a large value and the approximation does not impact the discovery latency largely. When n is small, we can compute the exact value of p t and derive the discovery probability.
We next show that maximizing p suc helps to achieve the lowest expected latency. Let W be a random variable that denotes the time a node spends discovering all neighbors. Considering any node, we define the time spent in discovering a new neighbor (the j-th node) after it discovered j − 1 neighbors to be W j , which follows a geometric distribution with parameter p suc (j): p suc (j) = (n − j + 1)p suc .
Hence, the expectation of W j can be computed as: Clearly, W = W 1 + W 2 + ... + W n which implies the time node u i discovers all neighbors; the expectation of W can be formulated as where H n is the n-th harmonic number, i.e., H n = ln n + Θ(1). By maximizing p suc , the lowest expected discovery latency becomes: When the duty cycle is a pre-defined parameter, the expected discovery latency can be bounded as Θ(n · ln n). Therefore, we can conclude the following theorem: Theorem 1. The Panacea-NCD algorithm ensures a node u i can discover all its n neighboring nodes within Θ(n · ln n) time slots with a high probability for a synchronous scenario.

Upper Bound Analysis of Discovery Latency
We show that the discovery latency is not likely to be much larger than its expectation, which can be utilized as the termination condition in Algorithm 1.
Recall the definition of W i in the above analysis; if W i is given, the value of W j will not be affected for i < j. That is, i = j, W i , and W j are independent and they satisfy P(W j = w j |W i = w i ) = P(W j = w j ). Since W j follows geometric distribution and Var[W j ] = 1−p j p 2 j , the variance of W can be computed as: According to the Chebyshev's inequality, we can derive the probability that the discovery latency exceeds the expected time by two times, as For a large n where n → ∞, and P[W ≥ 2E[W]] is close to 0. That is, the time for a node to find all neighbors is very likely to be smaller than 2 times the expected latency. Therefore we derive W = O(n · ln n). We can conclude the corollary as follows.
Corollary 1. The Panacea-NCD ensures a node u i can discover all its n neighboring nodes in O(n ln n) time slots a with high probability for a synchronous scenario when n → ∞.

Algorithm Analysis of Asynchronous Scenario
The proposed Panacea-NCD algorithm is suitable for asynchronous scenario where the sensor nodes are activated in different time slots. For node u i , denote the maximum activation time offset between u i and any neighbor is δ = max u j ∈NS(u i ) (t s i − t s j ). Denote the latency that u i finds a new neighbor after it discovered j − 1 neighbors as W j , and the latency that u i finds all neighbors as W .
It is obvious that the start time offset δ will not affect the latency, which implies Hence, we derive the expected latency for a node discovering all its neighbors as We can conclude that the expected discovery latency for an asynchronous scenario is δn slots larger than that for a synchronous scenario. When δ is a constant value, the expected discovery latency is also Θ(n · ln n). Similarly, we can also derive the probability that the discovery latency is 2 times larger than the expectation, as P[W ≥ 2E[W ]] is still close to 0; hence the discovery latency can be bounded by O(n · ln n) with high probability. Combining these, we conclude the following theorem: Theorem 2. The Panacea-NCD algorithm ensures a node u i can discover all its n neighboring nodes within Θ(n · ln n) slots in expectation and in O(n · ln n) slots with a high probability for an asynchronous scenario when n → ∞.

Remark 1.
We assume p n ∈ (0, 1) in our analyses for the following reasons. When p n = 0, it implies all nodes are completely separated and no node is connected with even one neighboring node; then it is meaningless to analyze the algorithm performance. When p n = 1, the network is fully connected which implies any node can communicate with all other nodes directly. The analyses can also be adopted to the situation. Since we define the network as a partially connected one, we assume p n < 1.

Analysis for Uniform Distribution
Uniform distribution is used in most deployments of wireless networks. For instance, to monitor an unknown area, many sensors are deployed uniformly to collect information, such as temperature and humidity [42]. The nodes are evenly deployed and the density function can be formulated as: where A is the area of D. For any node u i , denote the range of u i 's neighbors' positions as R i and any neighboring node with coordinate (x, y) ∈ R i suits (x − x i ) 2 + (y − y i ) 2 ≤ ∆ 2 , where (x i , y i ) is u i 's position. Then, node u i 's expected number of neighbors can be computed as Combining this in the Panacea-NCD's design, we can still derive the upper bound of discovery latency to be O(n · ln n) when n is large and compute the latency precisely.
We analyze the algorithm when the nodes have nearly the same number of neighbors for different network representations (including the uniform distribution). When the nodes obey some other distribution, the nodes may have a different number of neighbors and it would be an interesting future work. In addition, the analyses of the expectation and the upper bounds are derived when n is large. When n is small, these bounds may not hold but they show the increasing trend when n increases.

Panacea-WCD: Neighbor Discovery with Collision Detection
In this section, we propose Panacea-WCD algorithm, a novel random algorithm that achieves low latency for a given duty cycle when the nodes can detect collision.

Algorithm Description
If nodes could identify collisions, the transmitting node(s) could be notified whether transmissions are successful by their listening neighbors. We describe Panacea-WCD in Algorithm 2 and it works as follows: Each time slot is divided into two sub-slots. In the first sub-slot, nodes transmit, listen, or sleep and act in response to one of the three states. In the second sub-slot, nodes notify their neighbor(s) and maintain DiscoveredList to record the discovered nodes.
Initially, each node u i sets k i = 0, and α is a constant. For each time slot t, (1) In the first sub-slot, node u i transmits a message containing its source node ID with probability p t i = 1 n+αk i (Line 4), listens with probability p l i = θ i − p t i , and sleeps with probability p s i = 1 − θ i ; (2) In the second sub-slot, there are three sub-cases:

-
If u i selects the Listen state in the first sub-slot: if u i receives a message successfully, u i decodes and records the source ID in the message. If the ID does not belong to u i 's DiscoveredList, u i adds the ID to DiscoveredList, and deterministically transmits a message on the channel (a bit is sufficient) in the second sub-slot; -If u i selects the Transmit state in the first sub-slot: if u i detects energy (a message or a collision by multiple messages), u i is notified the successful transmission and sets k i := k i + 1, otherwise u i regards its transmission as unsuccessful in the first sub-slot; -If u i selects the Sleep state in the first sub-slot: u i does nothing in the second sub-slot.
The core of Panacea-WCD is that once u i discovers a new node u j that does not belong to its DiscoveredList, u i adds u j 's ID to its DiscoveredList and notifies u j of the successful discovery. In this successful scenario, u i 's feedback in the second sub-slot can be 1-bit. Thus, the second sub-slot is much smaller than the first one, and it only introduces a small overhead.
if r < p t i then 5: node u i transmits in the first sub-slot 6: if detects energy in the second sub-slot then 7: SuccessTransmission ← True, k i ← k i + 1 8: SuccessTransmission ← False 10: end if 11: else if p t i < r < θ i then 12: node u i listens in the first sub-slot 13: if Successful reception in the first sub-slot then 14: node u i decodes the message and the source ID (srcID) 15: if srcID not in DiscoveredList then 16 20: node u i sleeps in the first sub-slot 21: end if 22: end while

Algorithm Analysis of Synchronous Scenario
We also analyze the discovery latency from both expectation and upper bound aspects.

Expectation Analysis of Discovery Latency
Similar to Panacea-NCD, we suppose the latency to find a new neighbor after discovered j − 1 neighbors is W j . To simplify this analysis, we consider a node u i discovering neighbors at an average level, where the number of discovered neighbors follows a normal distribution. That is, some nodes that discover neighbors faster and slower tend to compensate for the number of discovered neighbors of each other. In other words, we have a global transmission probability p t (j) in W j , which is . (17) In a given time slot, the probability that u i discovers a new neighbor after it discovered j − 1 neighbors is As W j follows geometric distribution with parameter p suc (j), we choose α close to 1, 1 n+α(j−1) θ, and the latency expectation that u i discovers all neighbors W = ∑ n i=1 W i can be computed as: Because ∑ n j=1 n+α(j−1) n−j+1 = (α + 1)nH n − αn where H n is n-th harmonic number, we can obtain: n When θ is determined in advance, we can conclude the theorem as Theorem 3. The Panacea-WCD algorithm ensures a node u i can discover its all n neighboring nodes within Θ(n · ln n) time slots in expectation for synchronous scenario.

Upper Bound Analysis of Discovery Latency
We show that the latency is not likely to be much larger than its expectation. For i = j, W i and W j are independent by definition. As Var[W j ] = 1−p suc (j) p 2 suc (j) for geometric distribution with parameter p suc (j), we obtain: We know that ∑ n j=1 1 p 2 suc (j) ≤ e 2 θ 2 [α 2 n − 2αn(1 + α)H n + π 2 6 (1 + α 2 )n 2 ]; according to Chebyshev's inequality, we derive: The probability is close to 0 when n is large (n → ∞). Hence, the latency is not likely to be 2 times larger than the expectation. Therefore, we conclude the corollary as: Corollary 2. The Panacea-WCD ensures a node u i can discover its all n neighboring nodes in O(n ln n) time slots with high probability for synchronous scenario when n → ∞.

Algorithm Analysis of Asynchronous Scenario
For Panacea-WCD, we can also derive Equation (13) of latency expectation to discover a new neighbor after the discovered j − 1 neighbors. The expected latency for a node discovering all its neighbors is (α + 1)nH n θ We can derive E[W ] = Θ(n · ln n) for asynchronous scenario. Similarly to Panacea-NCD, the probability that the discovery latency is 2 times larger than the expectation is still close to 0. Hence, we conclude the following theorem: Theorem 4. The Panacea-WCD algorithm ensures a node u i can discover its all n neighboring nodes within Θ(n · ln n) slots in expectation and in O(n · ln n) slots with a high probability for an asynchronous scenario when n → ∞.
Notice that, when the proposed algorithm is deployed in realistic network technologies such as Zigbee and BLE Mesh, we have to adjust the algorithm if their collision detection mechanism is applicable. For example, Zigbee utilizes CSMA/CA to reduce collision, which is difficult to couple with Panacea-WCD, while BLE Mesh finishes events with a random delay, we may adjust the transmit and listen operations.

Remark 2.
The Panacea algorithm (including both Algorithm 1 and Algorithm 2) needs to know the average number of neighbors in advance. The introduced two network representations help identify this value. In practice, the sensors are deployed artificially or by some distribution (such as the uniform distribution in Section 4.4); it is reasonable to derive the number of neighbors beforehand. It would be an interesting future work to relax the limitation.

Evaluation
We implemented Panacea in C++ and evaluated the algorithms in a cluster with four nodes, each with an Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40 GHz, 12 cores, 128 GB memory, and 2 GB spinning disk. We used two different initialization methods to generate the networks. There are N sensor nodes in total and we set the maximum activation offset δ = 1000. The first method generates the neighboring matrix M N×N with probability p n , which implies node u i is the neighbor of any other node u j (i.e., M ij = M ji = 1) with probability p n . The second method assumes all nodes are deployed in an area of size 100 × 100 m by the uniform distribution and the communication range is ∆ = 10 m. Any two nodes u i , u j satisfying d(u i , u j ) ≤ ∆ are neighbors in the network. These two methods can generate the networks more complicated and realistic than that in [9,11,12,[14][15][16][17][18][19][20]22].
We evaluate discovery latency of Panacea, Coupon [20], Aloha-like [22], and PND [18] in the generated partially-connected networks in both synchronous and asynchronous scenarios. Since Coupon [20] and PND [18] do not consider duty cycle, we evaluate the tradeoff of duty cycle and discovery latency among Panacea, Aloha-like [22], and Hello [19]. We also compare the evaluation results with the theoretical analyses. The expected discovery latency of Panacea-NCD is derived as Equation (10) while the expected latency of Panacea-WCD is bounded by Equation (20). We set the length of each time slot as t 0 = 20 ms and the nodes are activated randomly within time [0, δ] for asynchronous scenario; the results are based on 1000 separate runs.

Partially-and Fully-Connected Networks
To begin with, we evaluate the performance of the algorithms in different settings. Though Panacea is proposed for partially connected networks, it can be also adopted in a fully-connected network. As shown in Figures 1 and 2, when the network is partially connected (p n = 0.1, 0.5), the algorithms use less time to discover the neighbors (y-axis, number of slots) compared to the fully connected setting when there are N = 1000 node in total. Among them, Panacea shows superior performance.

Comparison of Discovery Latency
We evaluate the performance of the proposed algorithms in different settings. In the first place, we generate the network with N = 1000 nodes and p n = 0.1. We compare Panacea with Coupon and PND when the nodes always turn their radios on (i.e., the duty cycle is 1). As shown in Figure 3a where y-axis represents discovery latency, i.e., the number of slots, Panacea-NCD could achieve the lowest discovery latency when the nodes do not have a collision detection mechanism, reducing time by about 60% and 92% when compared to Coupon and PND, respectively. Panacea-WCD also has the best performance when the node can detect collision as illustrated in Figure 3b; it reduces latency by about 30% and 90% compared to Coupon and PND, respectively. Coupon can achieve good performance in a fully-connected network, but it works worse than Panacea in a partially-connected network. We do not compare the Aloha-like algorithm because it is the same with Coupon when the duty cycle is 1. By setting different duty cycles in our algorithm, Panacea could save energy by 40% when it achieves similar discovery latency with Coupon.  We also evaluate the algorithms when the number of nodes increases from 100 to 1000. As depicted in Figure 4, when the network size increases (x-axis), the discovery latency (y-axis, number of slots) increases for all algorithms. This is because each node has more neighbors to discover and the communication collision occurs more often. We compare Panacea to Coupon and PND for four different scenarios regarding whether the nodes are activated synchronously and whether they have a collision detection mechanism. The results show that our algorithms have the best performance, achieving lowest discovery latency when the number of nodes increases. Figure 4a,b also depicts the derived expected discovery latency of Panacea-NCD, and the results show that the evaluations corroborate the theoretical analyses. Regarding Panacea-WCD, Figure 4c,d shows the upper bound and lower bound of the expected discovery latency and the evaluation results also corroborate the analyses.  When the network is generated according to the nodes' positions, we compare the neighbor discovery algorithms in Figure 5. When the nodes are deployed according to the uniform distribution and the number of nodes N increases from 100 to 1000, we also evaluate their performance for four different scenarios; the results show that the discovery latency increases when N increases and Panacea could achieve the lowest discovery latency among them. In addition, comparing with the expected discovery latency of Panacea, the evaluation results corroborate the theoretical analyses in Equation (10) and Equation (20). As analyzed, Panacea could achieve the lowest discovery latency because Coupon and PND cannot handle communication collision efficiently, while Panacea could reduce discovery latency by handling the collision in an appropriate way.

Comparison of Discovery Rate
We evaluate the discovery rate of the algorithms which is defined as the percentage of discovered neighbors. We first evaluate Panacea-WCD for a dense network p n = 0.5, N = 1000 and the duty cycle is θ = 0.5. Figure 6 shows the discovery rate (y-axis) increases as time (x-axis) increases. In the synchronous scenario, Panacea-WCD could reach 100% discovery rate, while Coupon reaches 79.2% and PND reaches 84.6%, respectively. This is because Coupon and PND simply regard the case of no collision as a success, ignoring that some neighbors of transmitting nodes fail to discover in the Sleep state. The results show the similar phenomenon in the asynchronous scenario.  We evaluate the discovery rate when N = 1000, θ = 0.5 and all nodes are uniformly distributed. As shown in Figure 7, Panacea achieves higher discovery rate than others; both Panacea-NCD and Panacea-WCD could reach 100% discovery rate. Coupon could reach (nearly) 100% discovery rate in some scenarios when the network is sparser than that in Figure 6; this is because Coupon is more applicable to a sparse network.  Figure 7. Panacea-NCD and Panacea-WCD achieve higher discovery rate for both synchronous and asynchronous scenarios under the uniform distribution.
These figures validate that Panacea could handle communication collision in the algorithm design and thus it achieves 100% discovery rate.

Tradeoff: Discovery Latency v.s. Duty Cycle
Since different applications could set different duty cycle values, we evaluate the tradeoff between discovery latency and duty cycle. When N = 1000, p n = 0.5, Figure 8 demonstrates that Panacea has a better tradeoff between discovery latency (y-axis, number of slots) and duty cycle (x-axis); the discovery latency is proportional to 1 θ for Panacea, which corroborates our analyses. The evaluated discovery latency of Panacea-NCD fits quite well with the expected discovery latency, while the evaluated latency of Panacea-WCD is also located within the lower bound and the upper bound of the expected latency. PND and Hello have higher latency, because PND's collision slots make up 46.5% of the time, and Hello's collision slots make up 99.8% of the time. The power-latency product [15] measurement is the product of the average power consumption with discovery latency. The power-latency product of Panacea is 9213, while that of Aloha-like is 20.3% larger, and PND is 2.69 times larger than Panacea in the synchronous scenario. The PND algorithm's performance is unstable when the duty cycle increases, this is because PND suffers from irregular collisions and the algorithm varies the sending probability according to different scenarios. In addition, we only measured the average discovery latency of 1000 separate runs.

Network Density
Finally, we evaluate the performance of Panacea when the network becomes denser. We fix N = 1000 and increase p n from 0.1 to 0.9; as shown in Figure 9, the discovery latency (y-axis, number of slots) increases for both scenarios (without or with collision detection). This is because collisions take place more frequently in denser networks. We depict three curves for different duty cycles (0.1, 0.3, and0.5, respectively); the results show that higher duty cycle contributes to lower latency, since discovery latency is proportional to 1 θ . The results validate that the discovery latency of Panacea is proportional to 1 θ and that a larger p n leads to larger latency due to the collisions. The evaluated results also corroborate the theoretical analyses of the algorithm. From these figures, the proposed Panacea algorithm can achieve a low discovery latency, a high discovery rate, and good tradeoff between discovery latency with duty cycle.

Conclusions
In this paper, we propose Panacea a low-latency and energy-efficient neighbor discovery algorithm for partially connected wireless sensor networks. First, we present Panacea-NCD for nodes without collision detection mechanism and we analyze that the discovery latency is bounded within O(n · ln n) time slots for any pre-defined duty cycle when n is large. Then, we modify this method in Panacea-WCD when nodes can detect collision. The discovery latency of Panacea-WCD is also bounded within O(n · ln n) slots for a large n. Our algorithms can be efficient in both synchronous and asynchronous scenarios because we alleviate collisions as much as possible. Furthermore, we verified our theoretical analyses by simulations and the results corroborate our analyses. Still, Panacea needs to know an average number of neighbors beforehand and that the nodes have the same number of neighbors, it would be important and interesting to relax such a priori knowledge in the future. In addition, we will evaluate the algorithms' performance in further practical applications.