# Enhancing the Reliability of Cellular Internet of Things through Agreement
## 5 Verification of The Optimality of CIoTAP  
In this section, the optimality of CIoTAP will be verified by mathematical method because the optimality is a theoretical problem. The complexity of CIoTAP will be evaluated based on the following two points, including: (1) the times of data exchange required by CIoTAP is the minimum, and (2) the maximum number of faulty PUs that can be allowed to exist when using CIoTAP to reach an agreement. Through the evaluation of these two factors, CIoTAP is proven to be the optimal solution to the agreement problem under the MECIoT framework. The times of data exchanges required to reach an agreement with CIoTAP is the minimum. By calculating the times of data exchanges required by each tier of MECIoT, the total times of data exchange times required by CIoTAP can be obtained. 1. _Access-tier_: In the _Access-tier_, each CIoT PU passes the received sensor data to the _MEC-tier_ during the Data Collection Stage. Therefore, only one time of data exchange is required. 2. _MEC-tier_: When CIoTAP is executed, data need to be exchanged only during the _Data Collection Stage_. According to the research results of [26] and [27], in a distributed system composed of \(n\) PUs, \(\lfloor(n-1)/3\rfloor+1\) is the minimum times of required data exchanges to send enough data to reach an agreement. Because in the _MEC-tier_ of MECIoT, there may be faulty MEC PUs. With reaching the agreement problem, each MEC PU in the _MEC-tier_ must exchange data with other MEC PUs. Therefore, the results of [26] and [27] can be applied to this study. In other words, there are \(n_{Mj}\) MEC PUs in MEC cloud \(E_{j}\) of _MEC-tier_, and CIoTAP needs \(\lfloor(n_{Mj}-1)/3\rfloor+1\) data exchanges. In the _E-_cloud _MEC-tier_, CIoTAP must to be executed by each MEC PU in the MEC cloud, where \(E\) is the total number of MEC clouds in the _MEC-tier_ of MECIoT. Therefore, the times of data exchanges for each MEC PU in all MEC clouds to perform CIoTAP depends on the number of MEC PUs in the MEC cloud. 3. _Cloud-tier_: As in the discussion of the times of data exchanges required in the _MEC-tier_. In the _Cloud-tier_, the research of [26] and [27] can still be applied. In _Cloud-tier_, there are \(n_{C}\) Cloud PUs in _Cloud-tier_, CIoTAP needs \(\lfloor(n_{C}-1)/3\rfloor+1\) times to exchange data. In other words, when there are \(n_{C}\) Cloud PUs in _Cloud-tier_, CIoTAP will be executed by \(n_{C}\) Cloud PUs. At this time, each Cloud PU needs to perform \(\lfloor(n_{C}-1)/3\rfloor+1\) times of data exchange first, and then the agreement is reached. From the above description, the CIoTAP proposed in this study in MECIoT requires the minimum times of data exchanges when reaching an agreement. In MECIoT, the number of faulty PUs that can be allowed when executing CIoTAP to reach an agreement is the maximum. MECIoT is divided into three tiers, so the calculation of the total number of allowable faulty PUs in CIoTAP can be discussed separately through the three tiers of MECIoT. 1. _Access-tier_: Since the number of faulty CIoT PUs in each coverage area of a specific BS in the _Access-tier_ cannot exceed half, the majority value of the data received by all normal CIoT PUs can be calculated, and this calculated value will be the agreement value in the coverage area of a specific BS. Therefore, \(n_{Bj}>\lfloor(n_{Bj}-1)/2\rfloor+f_{Bj}\) where \(n_{Bj}\) is the number of CIoT PUs and \(f_{Bj}\) is the total number of faulty CIoT PUs allowed within the coverage of a specific \(BS_{j}\) at the _Access-tier_. \(F_{A}\) is the total number of faulty CIoT PUs allowed in the _Access-tier_, \(F_{A}=\sum_{j=1}^{B}f_{Bj}\) where \(B\) is the total number of coverage areas of the BSs in the _Access-tier_, and \(f_{Bj}\) is the total number of faulty CIoT PUs allowed in the coverage of \(BS_{j}\). 2.