A Simple Algorithm For Replacement Paths Problem

A Simple Algorithm For Replacement Paths Problem

Anjeneya Swami Kare Department of Computer Science and Engineering
Indian Institute of Technology
Hyderabad, India
cs14resch01002@iith.ac.in

A Simple Algorithm For Replacement Paths Problem

Anjeneya Swami Kare Department of Computer Science and Engineering
Indian Institute of Technology
Hyderabad, India
cs14resch01002@iith.ac.in
Abstract

Let ( and ) be an undirected graph with positive edge weights. Let be a shortest path in . Let be the number of edges in . The Edge Replacement Path problem is to compute a shortest path in , for every edge in . The Node Replacement Path problem is to compute a shortest path in , for every vertex in .

In this paper we present an time and space algorithm for both the problems. Where, is the asymptotic time to compute a single source shortest path tree in . The proposed algorithm is simple and easy to implement.

Keywords:
Replacement Path, Replacement Shortest Path, Edge Replacement Path, Node Replacement Path, Shortest Path

1 Introduction

Let ( and ) be an undirected graph with a weight function on the edges. Let be a shortest path in . Let denote the number of edges in , also denoted by . The total weight of the path is denoted by , i.e, , where, is the edge . A shortest path tree (SPT) of rooted at (respectively, ) is denoted by (respectively, ).

A Replacement Shortest Path (RSP) for the edge (respectively, node ) is a shortest path in (respectively, ). The Edge Replacement Path problem is to compute RSP for all . Similarly, the Node Replacement Path problem is to compute RSP for all .

Like in all existing algorithms for RSP problem, our algorithm has two phases:

  1. Computing shortest path trees rooted at and , and respectively.

  2. Computing RSP using and .

For graphs with non-negative edge weights, computing an SPT takes time, using the standard Dijkstra’s algorithm [1] with Fibonacci heaps [2]. However, for integer weighted graphs (RAM model) [3], planar graphs [4] and minor-closed graphs [5], time algorithms are known. In this paper, to compute SPTs and (phase 1) we use the existing algorithms. For phase 2, we present an time algorithm which is simple and easy to implement.

Motivation for studying replacement paths problem is its relevance in single link (or node) recovery protocols. Other problems which are closely related to replacement paths problem are Most Vital Edge problem [6], Most Vital Node problem [7] and Vickrey Pricing [8]. Often an algorithm for replacement paths problem is used as a subroutine in finding -simple shortest paths between a pair of nodes.

Edge Replacement Path Problem
Reference Time Complexity
Malik et al. [9] (1989)
Hershberger and Suri [8] (1997)
Nardelli et al. [6] (2001)
Jay and Saxena [10] (2013)
Lee and Lu [11] (2014)
This Paper
Node Replacement Path Problem
Reference Time Complexity
Nardelli et al. [7] (2003)
Jay and Saxena [10] (2013)
Lee and Lu [11] (2014)
Kare and Saxena [12] (2014)
This Paper
Table 1: Summary of existing algorithms 222In the referenced papers, authors ignore the term , as they assume either shortest path trees are given or restriction on the input graph class for which linear time algorithms are known for SPTfor RSP problem

For the Edge Replacement Path problem Malik et al. [9] and Hershberger and Suri [8] independently gave time algorithms. Nardelli et al. [6] gave an time algorithm, where is the inverse Ackermann function.

For the Node Replacement Path problem Nardelli et al. [7] gave an time algorithm. Kare and Saxena [12] gave an time algorithm.

Jay and Saxena [10] gave an algorithm, where is the diameter of the graph. Their algorithm can be used to solve both the edge and the node replacement path problems. They used linear time algorithms for Range Minima Query (RMQ) [13] and integer sorting in their solution. A total of instances, each of RMQ and integer sorting has been used (with size of each instance at most ). Recently, Lee and Lu [11] gave an time algorithm. Table 1 summarises the existing algorithms for RSP problem.

In this paper, we present an time and space algorithm. The asymptotic complexity of our algorithm matches that of [10]. However, our solution does not use RMQ and integer sorting. Our algorithm organizes the non-tree edges of the graph in a simple manner. Moreover, an advantage of our algorithm over [10] and [11] is that, in a single iteration both edge and node replacement paths can be obtained, whereas in [10] and [11] the algorithm has to be run independently for the edge and node replacement paths. Note that, linear time algorithm for RMQ [13] and the algorithm in [11] are complex to implement. The simplicity of our algorithm makes it an ideal candidate for the RSP. In particular, for dense graphs and graphs with small diameter ()) our algorithm is optimal and matches with that of [11]. As observed in [10], graphs in real world data sets have small diameter, which further adds significance to our algorithm.

The contribution of this paper is summarized in the following theorem.

Theorem 1

There is an algorithm for the edge and the node replacement path problems that runs in time using space.

The rest of the report is organised as follows. In Section 2 we discuss the algorithm for the edge replacement path problem. In Seection 3 we discuss the algorithm for node replacement path problem. We conclude with Section 4.

2 Edge Replacement Paths

We start by computing shortest path trees and . In the rest of the section we describe the algorithm for computing RSP using and (phase 2).

A potential replacement path for the edge can be seen as a concatenation of three paths , and , where, for some , for some and as shown in Figure 1. Here, the symbol represents a path in . One extreme case is when and (i. e. and ) as shown in Figure 1(b). Such a replacement path is also a potential replacement path for all the edges . The other extreme case is when and (i.e. and ) as shown in Figure 1(c). Such a replacement path is a potential replacement path only for the edge .

Figure 1: Potential replacement paths for the edge . The zig-zag lines represent a path

Consider the shortest path tree rooted at (). When the edge is removed from , is disconnected into two sub-trees. (sub-tree rooted at ) and (sub-tree rooted at ). The vertex sets of and determine a cut in the graph . Let denote the set of all non-tree edges crossing the cut. These edges are called crossing edges, i.e, . In order to have a replacement path, the set needs to be nonempty. And, any replacement path must use at least one crossing edge from . Moreover, as we see from the Lemmas 2 and 3 there exists an RSP that uses exactly one crossing edge.

Lemma 2

For all , = and = .

Proof

If , then and . Shortest path is fully in and does not include the edge . Hence, = .

To prove , for the sake of contradiction, let us assume that (i.e ). It means that, uses the edge . This implies . Since , a contradiction. Hence, . ∎

Lemma 3

For any edge , there exists a shortest path in which contains exactly one edge from .

Proof

Let us consider a shortest path in (say ) which uses more than one crossing edge from . Let be the last crossing edge in . Clearly and . By replacing the part of from to , by the path in , we get a new path which is not longer than and uses exactly one edge from . ∎

Using the Lemmas 2 and 3, we write the total weight of the RSP for the edge as:

(1)

All the terms in the equation (1) are available in constant time for a fixed from and . Let be the crossing edge that minimizes the RHS of the equation (1). We call that the swap edge. If we have the swap edge, we can report the RSP as in constant time. Every non-tree edge can be a potential crossing edge for every edge in . So, solving equation (1) by brute force gives us time algorithm. In this paper we present an time algorithm. In the rest of the paper, we concentrate on computing the swap edge for each .

2.1 Labeling the nodes of

Every vertex of is labeled with an integer value from to , with respect to the shortest path tree . The process of labeling is as follows:

Let be the sub-tree rooted at the node in . All the nodes in the sub-tree are labeled with the integer value . For , all the nodes in the sub-tree are labeled with the integer value . See Figure 2(a) for an example labeling.

Using pre-order traversal on , we compute the labels of all the vertices in linear time. We start pre-order traversal from the source vertex using zero as initial label. While visiting the children of a node recursively, the child node part of (if any) will be visited last with an incremented label. Let denote the label of a vertex in . The following Lemma is straightforward.

Lemma 4

A non-tree edge if and only if and . In other words, for a non-tree edge , if and for some , then , .

2.2 Computing Swap Edges

We construct a directed acyclic graph which will aid us in computing the swap edges. We call this DAG as RSP-DAG, denoted by . The following algorithm explains the construction of the RSP-DAG. An example RSP-DAG is shown in Figure 2(b).

  {Adding Nodes. Each node is identified by an ordered pair }
1:  
2:  
3:  for  do
4:     for  do
5:        
6:     end for
7:  end for
  {Adding Edges}
8:  for each   do
9:     if  then
10:        
11:        
12:     end if
13:  end for
Algorithm 1 Algorithm to construct the RSP-DAG = .

Clearly, the number of vertices in the RSP-DAG is and the number of edges is also . Every node has in-degree and out-degree at most two. The node with identifier has zero in-degree. Nodes have zero out-degree (sink nodes).

Figure 2: (a)An SPT rooted at . Solid lines are part of the SPT. Dashed lines represent the non-tree edges (we omit the edge weights). Number inside the vertex circle denotes the vertex number, where as the number above the vertex circle represents vertex label.
(b)Corresponding RSP-DAG with set of non-tree edges associated with nodes

For each node , we associate a set of crossing edges. This set includes all the non-tree edges such that and . This association of crossing edges partitions the crossing edges into disjoint sets.

Lemma 5

If the swap edge for the tree edge is present in the edge set () of a node , then there exists a directed path from the node to the node in the RSP-DAG.

Proof

Clearly and , otherwise, will not be the crossing edge for . If is a sink node () in the RSP-DAG, then the theorem is trivially true.

Otherwise, if we observe the way edges are added in the RSP-DAG, for the node , two directed edges and are added and from these nodes, we keep adding edges to the lower level nodes in the RSP-DAG. We will eventually connect to the leaf node . Hence there is a directed path from to . ∎

Now we make a BFS traversal on the RSP-DAG starting from the node with identifier . During the traversal, at every node, the minimum cost non-tree edge (cost being ) from the corresponding edge set is inserted into the edge sets of its two children. By the end of this process, minimum cost non-tree edges in the respective sink nodes give us the swap edges.

Theorem 6

There is an algorithm for the Edge Replacement Path problem that runs in time using space.

Proof

represents the time to compute SPTs and . Construction of the RSP-DAG takes time and space. BFS traversal on the RSP-DAG takes time. During the traversal at each node , we extract the minimum cost non-tree edge from the set of size at most . Time complexity of overall edge extraction steps is: = . Therefore the total time complexity is . Space complexity is which is the space to store the RSP-DAG. ∎

Using the linear time algorithms for SPT, for integer weighted graphs, minor closed graphs our algorithm takes time.

3 Node Replacement Paths

When the node is removed, the SPT is partitioned as: (sub-tree rooted at ), (sub-tree rooted at ) and (the remaining forest ). The crossing edges are denoted as:

(2)
(3)
(4)
Lemma 7

For all , = , and for all , = .

Proof

We omit the proof as the proof is similar to lemma 2

Using Lemma 7, the length of the RSP is written as:

(5)
(6)
(7)

Having and , all the terms in the equations (5) and (6) are available in constant time, except the distance for (partial shortest path distance). We need all the partial shortest path distances , and .

To compute all the partial shortest path distances, we use the technique used in [10] and [11].

Let (corresponding to the vertex ) be the graph constructed from as follows: The vertex set of , , consists of the source vertex and the vertices which are part of the forest . The edge set of , , consists of the following edges:

  • Edges between the nodes within the forest . These edges will get the same edge weight as in .

  • For every , an edge is added whenever there is at least one edge from to . The weight of this edge is calculated as follows:

    (8)

That is,

(9)
(10)

is a graph minor of , since it can be obtained by edge contraction. Hence, SPT, of , rooted at can be constructed in time. Moreover, for any . As , for any , . Construction of and for all takes a total time of = . for any is available in constant time from of .

Instead of computing SPTs, , for all , we compute one graph, , where is constructed as explained earlier. can be constructed from in time. Single source shortest path tree rooted at , of is computed in time. for any is available in constant time from of . Moreover, as , the distances for all are available in linear time.

To compute for all , we use the RSP-DAG. We use the vertex labeling on (as computed in Section 2.1), for a non-tree edge , if and only if and . In other words, for a non-tree edge , if and for some , then , for all .

Hence, the crossing edges will be part of edge sets associated with the vertices in the RSP-DAG. After the BFS traversal on the RSP-DAG, the minimum cost crossing edge (over ) for is available in the edge set of the node in the RSP-DAG. We do not need to perform the BFS traversal on the RSP-DAG again, because, the data populated during the BFS traversal for the edge replacement paths suffices.

If we have the swap edge for the vertex , we can report the RSP in constant time as . Here is available from if . It is constructed from SPTs and if .

Theorem 8

There is an algorithm for the Node Replacement Path problem that runs in time using space.

Proof

represents the time to compute SPTs and . Computing the distances for all takes time. Computing for all using the RSP-DAG takes time and space. Therefore the total time complexity is . Space complexity is which is the space necessary to store the RSP-DAG. ∎

Using the linear time algorithms for SPT, for integer weighted graphs, minor closed graphs our algorithm takes time.

Proof of Theorem 1 is implied from theorems 6 and 8.

4 Conclusions

In this paper, we propose an time and space algorithm for the Replacement Paths problem. The asymptotic complexity of our algorithm matches with that of Jay and Saxena [10]. However, our algorithm does not require external algorithms RMQ and integer sorting and it is easy to implement. An advantage of our algorithm over [10] and [11] is that, in a single iteration both the edge and node replacement paths can be computed, whereas in [10] and [11] the algorithm has to be run independently for the edge and node replacement paths. For dense graphs and graphs with small diameter our algorithm is optimal and matches that of [11].

References

  • [1] Dijkstra, E.W.: A note on two problems in connection with graphs. Numerische Mathematik 1 (1959) 269–271
  • [2] Fredman, M.L., Tarjan, R.E.: Fibonacci heaps and their uses in improved network optimization algorithms. Journal of the ACM 34(3) (1987) 596–615
  • [3] Thorup, M.: Floats, integers, and single source shortest paths. Journal of Algorithms 35(2) (2000) 189–201
  • [4] Henzinger, M.R., Klein, P., Rao, S., Sairam: Faster shortest-path algorithms for planar graphs. Journal of Computer and System Sciences 55(1) (1997) 3–23
  • [5] Tazari, S., Muller-Hannemann, M.: Shortest paths in linear time on minor-closed graph classes, with an application to steiner tree approximation. Discrete Applied Mathematics 157(4) (2009) 673–684
  • [6] Nardelli, E., Proietti, G., Widmayer, P.: A faster computation of the most vital edge of a shortest path. Information Processing Letters 79(2) (2001) 81–85
  • [7] Nardelli, E., Proietti, G., Widmayer, P.: Finding the most vital node of a shortest path. Theoretical Computer Science 296(1) (2003) 167–177
  • [8] Hershberger, J., Suri, S.: Vickrey prices and shortest paths: What is an edge worth? In: Proceedings of the 42nd IEEE symposium on Foundations of Computer Science. (2001) 252–259
  • [9] Malik, K., Mittal, A.K., Gupta, S.K.: The most vital arcs in the shortest path problem. Operations Research Letters 8 (1989) 223–227
  • [10] Mahadeokar, J., Saxena, S.: Faster replacement paths algorithms in case of edge or node failure for undirected, positive integer weighted graphs. Journal of Discrete Algorithms 23 (2013) 54–62
  • [11] Lee, C., Lu, H.: Replacement paths via row minima of concise matrices. SIAM Journal on Discrete Mathematics 2(1) (2014) 206–225
  • [12] Kare, A.S., Saxena, S.: Efficient solutions for finding vitality with respect to shortest paths. In: 6th IEEE International Conference on Contemporary Computing (IC3). (2013) 70–75
  • [13] Berkman, O., Schieber, B., Vishkin, U.: Optimal doubly logarithmic parallel algorithms based on finding all nearest smaller values. Journal of Algorithms 14(3) (1993) 344–370
Comments 0
Request Comment
You are adding the first comment!
How to quickly get a good reply:
  • Give credit where it’s due by listing out the positive aspects of a paper before getting into which changes should be made.
  • Be specific in your critique, and provide supporting evidence with appropriate references to substantiate general statements.
  • Your comment should inspire ideas to flow and help the author improves the paper.

The better we are at sharing our knowledge with each other, the faster we move forward.
""
The feedback must be of minimum 40 characters and the title a minimum of 5 characters
   
Add comment
Cancel
Loading ...
84236
This is a comment super asjknd jkasnjk adsnkj
Upvote
Downvote
""
The feedback must be of minumum 40 characters
The feedback must be of minumum 40 characters
Submit
Cancel

You are asking your first question!
How to quickly get a good answer:
  • Keep your question short and to the point
  • Check for grammar or spelling errors.
  • Phrase it like a question
Test
Test description