3.2. clean Phase
Given an arc  that undergoes a decremental update, the clean phase aims at performing a more efficient regarding bidir–2hc, removal of outdated labels, by finding and removing all and only outdated label entries (from now on simply referred to as outdated entries) from the labeling, i.e., by avoiding to remove any correct entry. This is obtained by scanning the labels of vertices that are actually subject to entry removals and, contextually, by identifying pairs of vertices that might remain "uncovered" (i.e., without an hub in the labeling) after the removal of the mentioned incorrect label entries. This last identification step is necessary to test that the cover property for the new graph efficiently, in a next phase. The two purposes above are achieved, in detail, by:
determining two sets of vertices, named forward invalid hubs and backward invalid hubs, respectively, that are hubs for some pair in G but might stop being hubs in , due to the operation on , so to remove from L the incorrect entries associated with such vertices;
identifying and exploring two (virtual) subgraphs of the input graph, named forward cover graph and backward cover graph, respectively, and denoted by  and , respectively
In more details, to define our algorithm we give the following definitions.
Definition 1 (Forward Cover Graph). Given a graph , a 2-hop-cover labeling L of G, an arc . The forward cover graph  is a subgraph of G with  and  as vertex and arc sets, respectively, as follows:
a vertex u is in  if  and there exist two pairs  and  such that  (that is a shortest path from u to y includes  and h is a hub vertex for pair );
an arc  is in  if  and  (hence ).
 In other words, vertices of the forward cover graph are those with, in G, a shortest path toward y that might contain arc 
 and hence whose distance toward y might change as a consequence of a decremental operation occurring on 
. Please note that whether the distance toward y changes or not depends on the number of shortest paths from the vertex to y that are in the graph, and on the vertex ordering (see 
Figure 3a for a graphical example of two different vertices of the forward cover graph). Note also that the arcs of such graph are the arcs of a shortest-path arborescence of G rooted at x plus arc 
. Symmetrically, we define a backward version of the cover graph as follows.
Definition 2 (Backward Cover Graph). Given a graph , a 2-hop-cover labeling L of G and an arc . The backward cover graph  is a subgraph of G with  and  as vertex and arc sets, respectively, as follows:
a vertex u is in  if  and there exist two pairs  and  such that  (that is a shortest path from x to u includes  and h is a hub vertex for pair );
an arc  is in  if  and  (hence ).
 In other words, analogously to the forward case, vertices of the backward cover graph are those having, in G, a shortest path from x that might contain arc 
 and hence whose distance from x might change as a consequence of a decremental operation occurring on 
. Please note that again whether the distance from x changes or not depends on the number of shortest paths from the vertex from x that are in the graph, and on the vertex ordering. Note also that the arcs of such graph are the arcs of a shortest-path arborescence of 
 rooted at y plus arc 
 (a toy example of the structure of cover graphs for a given input graph is shown in 
Figure 3b).
Finally, we define the set of forward invalid hubs  (backward invalid hubs , respectively) of  as follows.
Definition 3 (Forward Invalid Hubs). 
Given a graph , a 2-
hop-
cover labeling L 
of G 
and an arc . Then, the set of forward invalid hubs  of  is defined as: Similarly, we give a backward version.
Definition 4 (Backward Invalid Hubs). 
Given a graph , a 2-
hop-
cover labeling L 
of G 
and an arc . Then, the set of backward invalid hubs  of  is defined as: Given the above definitions, algorithm clean’s strategy is based on the following properties. Notice that for the sake of simplicity, in what follows we use  or  to denote a vertex v belonging to the vertex set of either the forward or the backward cover graph.
Property 2. Let L be a 2-hop-cover labeling of G. Assume arc  is subject to a decremental operation and let  be the graph obtained by applying to G such modification. Let  (, resp.) be the forward (backward, resp.) cover graph. Then, for any vertex  such that  (, resp.) we have that  (, resp.) contains only correct entries for , that is for any  we have  (for any  we have , resp.).
 Proof.  By definition of forward cover graph, we know  implies there does not exist two pairs  and  such that  for some . Observe that for any 2-hop-cover labeling, , for some , implies . Now, by contradiction, assume an entry  is outdated, that is . This implies that the only shortest path from u to y in G includes arc  (since the update is decremental we have that  increases) and h is a hub vertex for pair . Hence we would have u is in the forward cover graph since there exist pairs  and  such that , which is a contradiction. The proof for the backward version is symmetric. □
 Corollary 1. For any pair  such that  and , we have that labeling L covers the pair also for , that is .
 Proof.  Consider that for any pair , since L is a 2-hop-cover labeling, we have . Moreover, having  and  implies both  and  contain only correct entries for . Therefore . □
 Hence, regardless of the magnitude of the change on , we are sure that the cover property is satisfied by L also in , for pairs  such that  and  and we do not need to search for outdated entries in outgoing labels of vertices of the forward cover graph nor in incoming labels of vertices of the backward cover graph.
Now, we establish how to determine which entries are outdated in the labels of the vertices of the two cover graphs. Please note that there can be labels of vertices of the two cover graphs that do not contain outdated entries. Still, we will show it is necessary to identify such vertices since they might be interested by violations of the cover property due to the removals of the above-mentioned outdated entries. This heavily depends on the structure of the shortest paths in the graph and on the effect of the decremental update on such structure, as shown in the example of 
Figure 4.
Property 3. Let  and  be the forward and backward cover graphs, respectively. Let L be a well-ordered 2-hop-cover labeling of G. Assume arc  is subject to a decremental operation and let  be the graph obtained by applying to G such modification. Let  and  be the sets of forward and backward invalid hubs. Then:
a label entry  in the outgoing label  of a vertex  is outdated if and only if  and there is no vertex  such that: (i) ; (ii) ; (iii) ;
a label entry  in the incoming label  of a vertex  is outdated if and only if  and there is no vertex  such that: (i) ; (ii) ; (iii) .
 Proof.  We focus on case 1. The proof for case 2 is symmetric.
(⇒) First of all observe that if  contains an outdated label entry  then, by Lemma 2, we must have  and hence we know that  and , i.e., v is connected in G to y via a shortest path that includes . By contradiction, we now assume that  is outdated but one of the two following conditions is true:
          
;
 and there is a vertex  such that: (i) ; (ii) ; (iii) .
Case 1. If , we have that h is not a hub vertex for pair  in L. This implies that there exists another hub vertex  that covers pair  which in turn implies that:
          
either ;
or  but h is not hub vertex (that is h does not belong to ) since  precedes both h and x in the vertex ordering ( and ) and since L is well-ordered.
In both sub-cases we obtain a contradiction, as  is not outdated (the decremental operation does not change the value of ).
Case 2. We have that there exists a neighbor of v, namely u, that is not in . Hence, its outgoing label, by Property 2, does not contain any incorrect entry and we have  for any . Therefore, as  and the weight of  does not change in , we have that  and thus the label entry  is not outdated, which is a contradiction.
(⇐) Again by contradiction we assume that there is a non-outdated (correct) entry  while  and there is no vertex  such that: (i) ; (ii) ; (iii) . Since  and  we know that . Now, since the entry is correct for , there must exist another shortest path, say P, in G that: (i) does not contain  and such that . Call  the neighbor of v on this second shortest path. Since there is no neighbor u such that  and , it follows that .
It follows that pair 
 is covered by some other vertex, say 
, such that 
 and 
. Since 
 we have also that h must be preceding 
 in the vertex ordering (i.e., 
) as otherwise the visit rooted at h would have not reached v (it would have been pruned thanks to 
). This is a contradiction since for the pruning on P to happen 
 must precede h. An explanatory example of this scenario is shown in 
Figure 5a. □
 To summarize, Properties 2–3 provide a theoretical basis upon which we design an effective algorithm for removing outdated entries, and for detecting pairs of uncovered vertices in , as we know that: (i) to find and remove (all and only) outdated entries it suffices to scan labels  (, resp.) of vertices  (, resp.) and to search for entries in the form  such that  ( such that , resp.); (ii) to find pairs of vertices  whose cover property can be broken in  due to removals of outdated entries, it suffices to determine vertices of  and ,
Therefore, the strategy of algorithm clean is divided in two steps. First, it computes sets  and , according to the definition (line 3 of Algorithm 3), and then it performs two suited visits of the input graph G (Algorithms 5 and 6) with the two-fold aim of identifying the vertices of the two cover graphs and removing outdated entries. These two sets are stored to evaluate, in a subsequent phase, whether the cover property in the new graph is satisfied or not.
| Algorithm 3: Algorithm clean | 
![Algorithms 13 00191 i002 Algorithms 13 00191 i002]()  | 
Specifically, each of the two visits start from the endpoints of the arc that is interested by the update (x and y, respectively), as shown in Algorithms 5 and 6, and proceed by determining vertices of the cover graphs on the basis of the corresponding conditions (see Definitions 1 and 2).
To limit the search to such vertices only, each visit employs a priority queue to drive the exploration in a shortest-path first fashion, starting from either x or y, and performs corresponding relax operations (see procedure 7 used in both Algorithms 5 and 6). This guarantees that vertices of the cover graphs are analyzed in order of distance from x or y and hence that entries are removed only if outdated.
In fact, whenever a vertex v of the forward (backward, resp.) cover graph is found, its outgoing (incoming, resp.) label is searched for entries in the form 
 for every 
 (
, resp.). If any entry of this kind is present, then the algorithm determines whether the entry is correct or not for 
 by looking at the outgoing (incoming, resp.) neighbors’ labels to establish whether there exists a second shortest path in G from v to h (from h to v, resp.), which is sufficient for the label entry to be correct in 
 (see 
Figure 5b).
If the search fails, then the entry is outdated and hence it is selected for removal (see line 12 of Algorithm 5 and line 12 of Algorithm 6) by adding the hub to a corresponding list (one per vertex, see line 17 of Algorithm 5 and line 17 of Algorithm 6). Otherwise, it is correct and hence it is preserved (see, e.g., line 13 of Algorithm 5). Once all vertices of the cover graphs have been found, and their label sets searched to select outdated entries, the visit terminates and both the lists of hubs corresponding to outdated entries and sets of vertices of the cover graphs are returned.
| Algorithm 4: Algorithm recover | 
![Algorithms 13 00191 i003 Algorithms 13 00191 i003]()  | 
The actual removal of outdated entries is performed then at this point, once the two visits are concluded, by sequentially scanning only the labels of vertices of the cover graphs that contain at least one outdated label entry (see lines 7–9 of Algorithm 3).
This is done for the sake of the efficiency, so to be able to test the membership of vertices of the cover graph and the presence of outdated entries in linear time, by exploiting the content of the 2-hop-cover labeling L of G (see, e.g., line 18 of Algorithm 5 or line 18 of Algorithm 6). The naive alternative to achieve the same purpose would be executing a traditional shortest-path algorithm (with possibly superlinear worst-case running time, e.g., Dijkstra’s).
We conclude the section by proving some results concerned with the correctness of Algorithm clean. In particular, first we show the two sets  and , computed by the algorithm, are exactly the two vertex sets of  and .
| Algorithm 5: Procedure fclean | 
![Algorithms 13 00191 i004 Algorithms 13 00191 i004]()  | 
| Algorithm 6: Procedure bclean | 
![Algorithms 13 00191 i005 Algorithms 13 00191 i005]()  | 
| Algorithm 7: Sub-Procedure RELAX used in Procedures fclean and bclean | 
![Algorithms 13 00191 i006 Algorithms 13 00191 i006]()  | 
Lemma 1. Let L be a minimal well-ordered 2-hop-cover labeling of a graph G. Let us assume that an arc  of G undergoes a decremental update. Let  (, resp.) be the forward (backward, resp.) cover graph. Then, if a vertex v is in  (in , resp.), we have that vertex v is added to set  by Algorithm 5 (to set  by Algorithm 6, resp.).
 Proof.  The proof is by induction on the number  of  operations on the queue . We first focus on Algorithm 5. Consider that at least one vertex is always inserted in the queue, namely x, with a priority of , the weight of the arc in G. Observe that  is a monotonically increasing value.
Base case (). The only time when we have  is when . Hence  and this shows the inductive basis since, if x is in  we have that  with . Therefore, the vertex is added to  by the algorithm. Please note that x is always added to .
Inductive Hypothesis. We assume the claim holds when , i.e., we have k extracted vertices that are in  and have been visited by Algorithm 5.
Inductive Step. We consider the case when . Observe that the next extracted vertex v must be a neighbor of some vertex, say , processed in one of the previous k iterations, as otherwise v would not be in . Moreover,  as v is the one with minimum priority. Therefore, we have that, if vertex v is in , in line 18, set  must be not empty, with  for some  (since any pair of vertices is covered by some hub h in L for G) and . Thus, the claim holds. □
 Then, we prove that all entries left in the labeling by Algorithm clean are correct for .
Lemma 2. Let L be a minimal well-ordered 2-hop-cover labeling of a graph G. Let us assume that an arc  of G undergoes a decremental update and let  be the resulting graph. Let  the labeling returned by Algorithm 3. Then, for any , all entries  are correct for , that is . Symmetrically, for any , all entries  are correct for , that is .
 Proof.  By contradiction, assume that there exists some entry , for some , that does not correspond to a shortest path in  after executing Algorithm 3, i.e., such that . Since  undergoes a decremental update, we must have that , as otherwise a first contradiction would be reached (either a decremental update is not increasing the distance or ).Moreover, we know  since L is a 2-hop-cover labeling therefore v must be a descendant of x in a shortest-path arborescence of G rooted at h, as otherwise  would not be in . Hence, by Lemma 1, vertex v must be in the forward cover graph  and hence is processed by Algorithm 3 in line 19. Thus, two cases can occur: either  or not. In the former case, the label entry is removed by Algorithm clean, which is again a contradiction. In the latter case, instead, we have that the shortest path from x to h in G did not contain , hence . Now, on the one hand, if the shortest path from v to h in G included , we reach a contradiction. In fact,  is removed, since  and hence  and . On the other hand, if the shortest path from v to h in G did not include , we obtain the contradiction of  being correct, since  not being on the shortest path from v to h implies . A symmetric argument can be used to show that all entries  are correct, for any , by considering the shortest-path arborescence of  and set . □
 Finally, we prove a slightly stronger property, which is the minimality of removals. Specifically, we can prove that no correct label entry is removed by Algorithm 3, i.e., the number of removals is minimal to remove all entries that do not correspond to shortest paths in . In what follows, given two labelings L and  we use  to denote the set of label entries that are in L but not in .
Lemma 3. Let L be a minimal well-ordered 2-hop-cover labeling of a graph G. Let us assume that an arc  of G undergoes a decremental update and let  be the resulting graph. Let  the labeling returned by Algorithm 3. Then,  does not contain any label entry that is correct for .
 Proof.  Assume by contradiction a correct label entry  is removed from , that is  contains, for some , pair  and . Call u the neighbor of v that induces the presence of such label entry in L which is well-ordered. Clearly we have that  and  since there must exist a neighbor on the shortest path from v to h (which is traversed, e.g., by fs–2hc).
Now, either the shortest path P from u to h contains arc 
 or not. In the latter case, we have that 
 and 
. Therefore, in line 13 of Algorithm 5 the label entry is not selected for removal, which is a contradiction. In the former case, as the entry is correct for 
, there must exist another shortest path, say 
, that does not contain arc 
 and such that 
. Call 
 the neighbor of v on such path, i.e., 
 and 
. Since the label entry is removed, it follows that Algorithm 5 in line 12 does not find any neighbor of 
 satisfying 
, i.e., 
 cannot have 
 in 
. Therefore, the visit rooted at h has not reached 
 due to some pruning test. It follows that pair 
 is covered (on 
) by some other vertex, say 
, such that 
 and 
. Since 
 we have also that h must be preceding 
 in the vertex ordering (i.e., 
) as otherwise the visit rooted at h would have not reached v (it would have been pruned thanks to 
). This is a contradiction since, for the pruning on 
 to happen, vertex 
 must precede h (an explanatory example of the scenario discussed in this proof is shown in 
Figure 6a). A symmetric argument can be used to prove that no correct label entry is removed from any incoming label 
. □
   3.3. recover  Phase
The second phase of Algorithm queue–2hc, named recover, takes place after Algorithm clean is concluded and considers sets  and  with the aim of restoring the (possibly broken) cover property for the new graph . The procedure, shown in Algorithm 4, takes as input also  and the labeling returned by Algorithm clean, say , and works by resuming a series of forward and backward shortest-path visits, each considering as root one of the vertices in sets  and  (i.e., vertices of forward and backward cover graphs), in the order imposed by the vertex ordering. Please note that in the remainder of the paper, given a vertex , we denote by  the index of h in said ordering. Each visit, rooted at some vertex , has the purpose of checking whether the cover property is satisfied for pairs  for any other  and, in case it is not, to restore it. This is done by visiting only the vertices and the arcs of the forward and backward cover graphs, as discussed in the following. The above is possible thanks to the following property on the labeling, holding after the execution of Algorithm clean.
Property 4. Let  and  the forward and backward cover graphs, respectively. Let  be the labeling returned by Algorithm 3 when applied to G, to its 2-hop-cover labeling L, as a consequence of a decremental update on arc . Then, for any pair  such that  or , we have that labeling  covers pair  also for , that is .
 Proof.  By contradiction assume for a pair  such that  (while v can be of any kind) we have that labeling  does not cover the pair for , i.e.,  (the case when u can be of any kind while  is symmetric). Notice that by Lemma 2 we know that entries in  are all correct for . Now, only three cases can occur: (i) ; (ii) ; (iii)  and . Notice in fact that by the definition of cover graphs, we cannot have that  and .
Case (i). Both u and v are in  hence we know that the shortest path in G between u and v does not contain . Furthermore, it is straightforward to see that the shortest path from u to v is made of only vertices in  (by contradiction, otherwise u cannot be in ). Hence the hub, say h covering the pair must be in  as well. Therefore h is not in  thus it cannot be removed from  by Algorithm 5. Moreover,  is not changed by Algorithm 5. Hence, we reach the contradiction of .
Case (ii). We know the shortest path from x to v in G included arc . We can distinguish two sub-cases: either the hub h covering pair  in G belongs to such path or not. In the former case, we have that  and hence also the shortest path from u to h in G must include . This implies that  since there must exist two pairs  and  such that  and  (that is there must exist an  that is a hub vertex for pair ) which is a contradiction. In the latter case, the shortest path from u to h in G does not include  and neither the shortest path from h to v in G. Hence, by Lemma 3, correct entries  and  must be in  and , respectively, which implies the pair is covered and the contradiction is reached.
Case (iii). As with case (i), we have that the shortest path in G between u and v does not contain  and that both labels  and  are not changed by Algorithm 5. Hence, again we have the contradiction of with . □
 By Property 4 it emerges that to guarantee the property holding for 
, it suffices to restart some shortest-path visits as follows. Given a root vertex 
 (
), all vertices 
 (
, respectively) are first analyzed in order to find 
viable neighbors for h. A viable neighbor 
 (
, respectively) is a neighbor such that: (a) 
 (
, respectively) and (b) 
 (
, respectively). For all such neighbors, we know that after the execution of Algorithm 
clean, there exists at least one shortest path from u to h (from h to u, respectively) that did not contain 
 in G. Clearly, there can be many viable neighbors (see 
Figure 6b). Therefore, to correctly discover distances corresponding to shortest paths, the procedure selects the one with a minimum distance encoded in the label entry. In particular, if we call 
 then the algorithm inserts v into a queue 
Q with priority 
 (see Algorithm 4). If no viable neighbor exists in 
, then the vertex is not inserted in the queue. Observe that the search for viable neighbors can be accelerated by skipping vertices according to their ordering and to the well-ordered property (see lines 5–8 or lines 18–21) that guarantees that if 
 then 
 and 
.
        
| Algorithm 8: Procedure  used by Algorithm recover | 
![Algorithms 13 00191 i007 Algorithms 13 00191 i007]()  | 
Once all vertices in 
 (
, respectively) has been treated as above, we have that 
Q contains vertices in 
 (
, respectively) with at least one viable neighbor, i.e., connected to the vertex h under consideration through a path that is not including 
. If 
Q is empty, it follows that no such vertices exist, and hence it is easy to see that the decremental operation must be an arc removal that has increased the number of strongly connected components of G (otherwise we would have that at least vertex x has vertex y as viable neighbor). Therefore, vertices in 
 (
, respectively) are not connected to (are not reachable from, respectively) h and hence the visit for h can terminate. If Q is not empty instead, the vertex v with minimum priority, say 
, is extracted and, if 
 (or 
, respectively) then new label entry 
 is added to 
 (
, respectively). In particular, if the value of 
 is smaller than the distance returned by 
pQ, it follows that the shortest path being discovered is not encoded in the labeling, i.e., that pair 
 is not covered by L. Please note that the pruning test considers vertices up to index 
 in the ordering, as done by 
resume–2hc to preserve minimality of the labeling (see [
8] for more details on 
prefixal correctness). Now, if a new label entry is added, then only the neighbors of v that are in 
 (
, resp.) are scanned in a relaxation step (see Algorithm 8) to add them to the queue or to decrease their key. In fact, vertices outside 
 (
, resp.) by Lemma 2 already satisfy the cover property to h. The algorithm terminates when the queue is empty for all vertices in 
 and 
. We are now ready to conclude the proof of correctness of Algorithm 
queue–2hc.
Theorem 1. Let  and  the forward and backward cover graphs, respectively. Let  be the labeling returned by Algorithm 4 when applied to graph , labeling  and set  and , respectively. Then,  is a minimal well-ordered 2-hop-cover labeling that covers , i.e., for any pair  we have .
 Proof.  First of all, observe that any pair that can have the cover property not satisfied for  (see Property 4) is considered by Algorithm recover, either in line 5 or in line 8.
We focus on proving the claim for all pairs  for a given vertex  (the proof for the case  is symmetric). The proof is by induction on the number  of  operations on the queue . Observe that if  we have that no vertex  has at least one viable neighbor. It is easy to see that this implies none of such vertices are reachable, in , from h in . In fact, any viable neighbor, say w, is outside  hence pair  is covered by  by Lemma 4. Moreover, all entries in  are correct. Thus,  and the claim holds.
Base case (). In this case, we have that one vertex, say w, has a viable neighbor and . By Lemma 2 it follows that  and hence the cover property is tested in line 27. If  is smaller than , a label entry  is added to  thus the claim follows. Otherwise, we have that  which, in turn, implies that  by the definition of pQ.
Inductive Hypothesis. We assume the claim holds when , i.e., we have  and  for any vertex t among the k vertices that have been extracted up to this point.
Inductive Step. We consider the case when . Observe that the next extracted vertex v must be a neighbor of some vertex, say , processed in one of the previous k iterations, as otherwise v would not be in . Therefore, we have that , as otherwise either v would not be extracted to be the minimum, or  would not be among the previously extracted vertices. Therefore, two cases can occur: either  is smaller than  or not. In the former case, a label entry  is added to  thus the claim follows. In the latter case, again we have that  which, in turn, implies that  by the definition of pQ and this concludes the proof. □