Article A Multi-Threading to Detect and Remove Cycles in Vertex- and Arc-Weighted Digraph

Huanqing Cui 1,2,3,* ID , Jian Niu 1,2, Chuanai Zhou 4 and Minglei Shu 2

1 College of and Engineering, Shandong University of Science and Technology, Qingdao 266510, China; [email protected] 2 Shandong Provincial Key Laboratory of Computer Networks, Shandong Computer Science Center (National Supercomputer Center in Jinan), Jinan 250101, China; [email protected] 3 Shandong Province Key Laboratory of Wisdom Mine Information Technology, Shandong University of Science and Technology, Qingdao 266510, China 4 Business School, Qingdao Binhai College, Qingdao 266555, China; [email protected] * Correspondence: [email protected]; Tel.: +86-532-8605-7852

Received: 28 August 2017; Accepted: 9 October 2017; Published: 10 October 2017

Abstract: A graph is a very important structure to describe many applications in the real world. In many applications, such as dependency graphs and debt graphs, it is an important problem to find and remove cycles to make these graphs be cycle-free. The common algorithm often leads to an out-of-memory exception in commodity personal computer, and it cannot leverage the advantage of multicore computers. This paper introduces a new problem, cycle detection and removal with vertex priority. It proposes a multithreading iterative algorithm to solve this problem for large-scale graphs on personal computers. The algorithm includes three main steps: simplification to decrease the scale of graph, calculation of strongly connected components, and cycle detection and removal according to a pre-defined priority in parallel. This algorithm avoids the out-of-memory exception by simplification and iteration, and it leverages the advantage of multicore computers by multithreading parallelism. Five different versions of the proposed algorithm are compared by experiments, and the results show that the parallel iterative algorithm outperforms the others, and simplification can effectively improve the algorithm’s performance.

Keywords: digraph; cycle detection and removal; vertex- and arc-weighted; multi-threading; iteration

1. Introduction Graphs can describe many applications in the real world, such as social networks, communication networks, dependency among software packages, and debt networks, and detecting cycles in a graph is a fundamental algorithmic problem. However, the existing solutions cannot handle large-scale digraphs using single commodity personal computers (PC), because they often lead to out-of-memory exceptions. This paper presents a multi-threading parallel and iterative algorithm of detecting and removing cycles, and this algorithm can take full advantage of multicore PCs. The main contributions of this paper include:

• It defines a new problem of detecting and removing cycles in a vertex- and arc-weighted digraph according to vertices’ priority. • It presents a multi-threading parallel and iterative algorithm to solve the problem. The algorithm avoids the out-of-memory exception by simplification and iteration, and it leverages the advantage of multicore computers by multithreading parallelism. • It performs thorough experiments to show the performance of the proposed algorithm.

Algorithms 2017, 10, 115; doi:10.3390/a10040115 www.mdpi.com/journal/algorithms Algorithms 2017, 10, 115 2 of 14

The organization of the rest of paper is as follows. Section2 presents the related work. Section3 introduces the problem. Section4 presents the detail of proposed algorithm and time complexity analysis. Section5 illustrates the performance comparison among five different versions of the proposed algorithms, using randomly generated graphs and real world digraphs. The final section contains conclusions and discussions.

2. Related Work Many literatures have focused on the cycle detection of a directed/undirected graph. Hamiltonian cycle is a special cycle that covers each vertex exactly once. The decision problem of whether a graph contains Hamiltonian cycle is NP-complete, so [1] presents some conjectures. A non-recursive algorithm to detect Hamiltonian cycle is presented in [2], and this algorithm is applied to flow-shop scheduling problem. Another two important cycles are the shortest and longest cycles of a graph, because they decide the girth and diameter/circumference of a graph, respectively. An approximate algorithm is given in [3] to find the shortest cycle in an undirected unweighted graph, whose expected time complexity is between O(nlogn) and o(n2), where n is the number of vertices of a graph. The algorithm presented in [4] aims to find the shortest cycle for each vertex in a graph. In a non-Hamiltonian graph, the longest cycles through some special vertices are discussed in [5–7], where [5] focuses on the longest cycles through large degree vertices, while [6,7] pay attention to the longest cycles passing all vertices of degree at least a given threshold. Besides characterizing or detecting special cycles of a graph, enumerating and counting cycles is also an important problem. Some explicit formulae for the number of 7-cycles in a simple graph are obtained in [8]. Recently, distributed algorithms to count or enumerate cycles are presented in [9], in order to solve this problem more efficiently. Sometimes a graph is dynamic, it grows by arc insertions. For this kind of graphs, the cycle detection problem is referred to as incremental cycle detection. Two online algorithms are presented 2 5 in [10] to solve this problem, which handle m arc additions for n vertices in O(m 3 ) and O(n 2 ) time, respectively. The algorithms presented in [11] are designed for sparse and dense graphs, which take 1 2 O(min{m 2 , n 3 }) and O(n2logn) time, respectively. Most of the above algorithms are based on DFS (Depth-First Search), which is inherently sequential [12], and they often cause out-of-memory exception when they are run on commodity PCs to solve large-scale graphs. Recently, many parallel and distributed graph-processing algorithms have been proposed. A message-passing algorithm is presented in [13] to count short cycles in a graph. The distributed cycle detection algorithm proposed in [14] is based on the bulk synchronous message passing abstraction, which is suitable for implementation in distribute graph processing systems. The cloud computing systems breed parallel graph processing platforms, such as Pregel [15], GraphX [16], and GPS [17]. These platforms are based on the BSP (Bulk Synchronous Parallel) model, which depends on costly distributed computing systems. Therefore, PCs cannot play to these algorithms’ strengths. The purpose of this paper is to propose an algorithm of detecting and removing cycles of large-scale digraphs using a single commodity PC.

3. Problem Statements

A digraph or directed graph G consists of a finite set of vertices V = {v1, v2, ···}, and a set of directed arcs E = {hvi, vji vi ∈ V, vj ∈ V, i 6= j} that each connects an ordered pair of vertices. Each arc hvi, vji ∈ E is associated with a numerical weight wij. Each vertex vi is also associated with an integer priority pi, and for any i 6= j, pi 6= pj. We denote the set of arc weights and vertex priorities by W and P, respectively. Given hvi, vji ∈ E, vi is called the tail, and vj is called the head of the arc. For a vertex vi , the number of head ends adjacent to vi is called its in-degree, and the number of tail ends adjacent to vi is its out-degree. Algorithms 2017, 10, 115 3 of 14

In a digraph, a directed path is a of vertices in which there is an arc pointing from each vertex in the sequence to its successor in the sequence. A simple directed cycle is a directed path where the first and last vertices are the same, and there are no repeated arcs or vertices (except the requisite repetition of the first and last vertices). Let C = {v1, v2, ··· , vk, v1} be a simple directed cycle, we define its cycle weight wC as

Algorithms 2017, 10, 115 wC = min{ wij hvi, vji ∈ C }.3 of 14 (1)

TheIn problem a digraph, of detectinga directed cyclespath is ina sequence such a vertex- of vertices and in arc-weighted which there is digraphan arc pointing is defined from as each follows. Givenvertex a digraph in the sequenceG = (V, toE, itsW ,successorP), the vertex in the sequence. A simple directed cycle is a directed path where the first and last vertices are the same, and there are no repeated arcs or vertices (except the requisite repetition of the first and last vertices).vbeg = Letargmin ={{p,i|p,⋯,i ∈ P},,} be a simple directed cycle, we (2) v ∈V define its cycle weight as i =〈,〉 ∈. (1) is chosenThe as theproblem beginning of detecting vertex tocycles detect in such cycle. a “argmin”vertex- and gets arc-weighted the vertex digraph with the is minimal defined weight.as Supposefollows.vcur Givenis the a currentdigraph visiting=(,,,) vertex,, thethe nextvertex vertex to visit should be

=argmin{| ∈}, ∈ (2) vnext = argmin{ pi|pi ∈ P }. (3) is chosen as the beginning vertex to detect cycle.vcur, v i“argmin”∈E gets the vertex with the minimal weight. Suppose is the current visiting vertex, the next vertex to visit should be v C v Once beg is visited again, a cycle =argminbeg is detected{| whose∈}. first and last vertices are both (3)beg . Next, 〈,〉∈ this cycle’s weight wCbeg is calculated by Equation (1). Finally, Cbeg is removed by subtracting wCbeg Once is visited again, a cycle is detected whose first and last vertices are both . from all arcs of this cycle, so that the arcs of weight wC are deleted from G. Repeat this procedure Next, this cycle’s weight is calculated by Equationbeg (1). Finally, is removed by until there are no cycles in G. The characteristics of this problem are: subtracting from all arcs of this cycle, so that the arcs of weight are deleted from . • RepeatThe cycles this procedure are detected until according there are no to cycles the vertex in . The priority. characteristics The first of andthis problem last vertices are: of the cycle •should The be cycles the vertexesare detected of minimal according priority, to the vertex and the priority. next vertex The first to visitand last from vertices current of onethe cycle should be the oneshould with be minimalthe vertexes priority of minimal in all priority, of the direct and th successors.e next vertex to visit from current one should • Thebe cycles the one are with removed minimal according priority in to all the of the arc direct weight. successors. The arcs with cycle weight are deleted to •destroy The thecycles cycle. are removed according to the arc weight. The arcs with cycle weight are deleted to destroy the cycle. This problem stems from removing the dependency chain in weighted dependency graph [18] and This problem stems from removing the dependency chain in weighted dependency graph [18] debt chain in financial field. Taking debt chain as an example, the debt relationship among enterprises and debt chain in financial field. Taking debt chain as an example, the debt relationship among G v ∈ V can beenterprises formulated can be as formulated a weighted as a digraph, weighted as digraph, defined as above.defined above. In a graph In a graph, (1) , each(1) each vertex vertex stands for an enterprise; (2) each arc hv , v i ∈ E stands for a debt relationship between corresponding ∈ stands for an enterprise; (2) ieachj arc 〈,〉 ∈ stands for a debt relationship between h i enterprisescorresponding and means enterprisesvi owes andvj; (3)meanswij associated owes ;with (3) v i,associatedvj is the amountwith 〈, of〉 debt is the of amount corresponding of enterprises;debt of and,corresponding (4) pi of vertex enterprises;vi represents and, (4) the importance of vertex of therepresents corresponding the importance enterprises, of the and the smallercorrespondingpi has the higherenterprises, priority. and Thisthe smaller kind of digraph has the higher is called priority. a debt This graph kind for of convenience. digraph is called Figure 1 illustratesa debt angraph example for convenience. including Figure 12 enterprises. 1 illustrates Debtan example cycle isincluding a simple 12 directedenterprises. cycle Debt in cycle a given is a debt graph.simple It is verydirected useful cycle to in solve a given the debt debt graph. problem, It is becausevery useful the to enterprises solve the debt belonging problem, to because a debt cyclethe can solveenterprises their debts belonging without to transferring a debt cycle capital.can solve their debts without transferring capital.

1, 2, 3, 38817 10098.98 10 1 9 15000 9988 4, 16000 11 50 100222 borrower lender 29847 v1 v2 w1,2 5, 6, 8, 9, p1 p2 10776 444 109 4 5 3 2 8710 11, 7, 7 8 1987.3 381.3 6751.35 10, 12, 8761.1 98761.1 12 6

(b) (a)

FigureFigure 1. 1.An An example exampleof of debtdebt graph. (a (a) )A A debt debt graph; graph; (b) (legend.b) legend.

4. Cycle Detection and Removal with Vertex Priority Algorithm 1 shows the sketch of the proposed algorithm, and its details are given next. Algorithms 2017, 10, 115 4 of 14

4. Cycle Detection and Removal with Vertex Priority Algorithm 1 shows the sketch of the proposed algorithm, and its details are given next.

Algorithm 1. Detect and Remove Cycles of a Weighted Digraph Step1: Simplify G. Step2: Divide G into strongly connected components. Step3: Detect, output and remove cycles of each strongly connected component.

4.1. Graph Simplification In Algorithm 1, line 1 simplifies the given graph G by deleting the vertices and arcs that do not belong to any cycle. This step aims to decrease the scale of the graph, especially when G is sparse. In fact, many graphs derived from real world are sparse [19]. Table1 shows seven digraphs taken from SNAP (Stanford Network Analysis Platform) [20]. We can see that more than 50% of vertices having zero in- or out-degree. The debt graph is sparser than these graphs, as shown in Section 5.3.

Table 1. The sparse characteristic of Stanford network analysis platform (SNAP) graphs.

Graph p2p-Gnutella04 p2p-Gnutella25 p2p-Gnutella30 p2p-Gnutella31 Email-EuAll Web-NotreDame Wiki-Talk Name |V| 10,876 22,687 36,682 62,586 265,214 325,729 2,394,385 |E| 39,994 54,705 88,328 147,892 420,045 1,497,134 5,021,410 ratio 1 54.80% 74.06% 74.12% 74.29% 95.79% 57.65% 94.88% 1 “ratio” is the ratio of vertices of out- or in-degree 0 to |V|.

Proposition 1. Given a digraph G = {V, E, W, P} , a vertex v ∈ V does not belong to any cycle if its out-degree or in-degree is 0.

According the above proposition, Algorithm 2 shows the simplification process. It first gets the in- in and out-degrees of vertices (lines 2–5). The while loop (lines 7–18) repeats deleting vertices of di = 0 out or di = 0, and their corresponding arcs. Lines 8~14 find the first vertex vk satisfying Proposition 1. If such a vertex exists (line 15), it calls Algorithm 3 to delete this vertex. Algorithm 3 uses two for loops to delete the arcs associated with u (lines 2–5 and 6–9) and u itself (line 10).

Algorithm 2. Simplify a Weighted Digraph

1. Function SIMPLIFY(G) 2. for all vi ∈ V do in 3. di ← in degree of vi out 4. di ← out degree of vi 5. end for 6. k ← 1 7. while k > 0 do 8. k ← 0 9. for i ← 1 to |V| do in out 10. if vi ∈ V ∧ (di = 0 ∨ di = 0) then 11. k ← i 12. break 13. end if 14. end for 15. if k > 0then 16. DELETE(G, vk) 17. end if 18. end while 19. return G 20. end function Algorithms 2017, 10, 115 5 of 14

Algorithm 3. Delete a Vertex from a Weighted Digraph

1. Function DELETE(G, u) 2. for all vi, u ∈ E do 3. E ← E − {vi, u} out out 4. di ← di − 1 5. end for 6. for all hu, vji ∈ E do 7. E ← E − {hu, vji} in in 8. dj ← dj − 1 9. end for 10. V ← V − {u} 11. end function

4.2. Cycle Detection

Proposition 2. Given a digraph G = {V, E, W, P}, if {v1, v2, ··· , vk, v1} is a directed cycle, then these vertices belong to the same strongly connected components of G.

This is the basis of step 2 of Algorithm 1. There are several efficient algorithms to calculate strongly connected components (SCCs) of a digraph, so we do not discuss the detail of step 2 of Algorithm 1. After SCCs are obtained, the cycles can be detected in each SCC. The cycle calculation is the core of Algorithm 1. Because the problem needs visit the vertices according their priorities, cycle should be detected using DFS. For large-scale graphs, the recursive DFS will cause out-of-memory exception, so we need an iterative version. The following data structures are adopted. Stack S is used to store the visited sequence of vertices. Its interfaces include:

• PUSH(S, v) to push v into S. • POP(S) to pop an element of S. • PEEK(S) to return the top element of S without popping out it. • SEARCH(S, v) to return the index of v in S, and it returns −1 if v is not in S. • CLEAR(S) to clear the S to empty. • SUBLIST(S, m, n) to return the sub-sequence of S from index m to n (m ≤ n). • ISEMPTY(S) to return false if S is not empty, and return true if S is empty.

Key-value pair table T is applied to record each neighbor vertex of a visited vertex is visited or not. As shown in Figure2, each key ( vi, i = 1, 2, ··· , n) is a vertex that is unique in the whole table. Each vi has a list of values, and each value is either 0 or 1 representing the corresponding neighboring vertex of vi is unvisited or not. It has the following interfaces:

• CLEAR(T, v) to reset all values of key v to 0. • SUM(T, v) to return the sum of values of key v. The sum represents the number of neighboring vertices have been visited until now. • GETFIRST(T, v) to return the first unvisited neighboring vertex of v. • SET(T, v, u) to set the value of neighboring vertex u of v to 1.

Minimum heap H is applied to store vertices based on their priorities, due to the high-efficiency of sorting and deleting members in heap. It only has one function, GETFIRST(H), to get the vertex of the highest priority. Algorithm 4 gives the cycle detection algorithm. It is a multi-threading parallel algorithm. Line 2 forks threads, and all of the threads run in parallel (line 4). Each thread gets an SCC (line 5), and calls FUN to detect and remove cycles (line 6). Algorithms 2017, 10, 115 6 of 14

The set of vertices VSCC is stored in a minimum heap H. The outer while loop (lines 12~40) detects cycles starting from each vertex of VSCC. Lines 13~17 initialize variables. For a given vertex, u, the inner while loop (lines 18~36) detects all of the cycles including u. Let v be the top element of S. If all its neighbor vertices are visited (line 20), pop it out and clear the status of all its neighbor vertices. Otherwise, get the first unvisited neighbor vertex r of v and visit it. In further, if r is not in S (line 27), r is pushed into S. If r is in S and r = u (line 29), than the sub-list of S from r to the top element is a cycle. If u cannot find any cycle, delete it from graph (line 38).

Algorithm 4. Detect Cycles of a Weighted Directed Graph

1. Function DETECTCYCLE(G) 2. Fork K threads 3. SC ← Φ 4. for each thread do in parallel 5. GSCC ← the next SCC to detect and remove cycle 6. SC ← SC ∪ FUN(GSCC) 7. end for 8. return SC 9. end function 10. Function FUN(GSCC) //GSCC = {VSCC, ESCC, WSCC, PSCC} is a SCC of G, VSCC is in heap H 11. SSC ← Φ 12. while VSCC 6= Φ do 13. u ← GETFIRST(H) 14. CLEAR(S) 15. CLEAR(T, u) 16. PUSH(S, u) 17. flag← false 18. while (flag=false and ISEMPTY(S)=false) 19. v ← PEEK(S) out 20. if |SUM(T, v)|= dv then 21. POP(S) 22. CLEAR(T, v) 23. else 24. r ← GETFIRST(T, v) 25. SET(T, v, r) 26. k=SEARCH(S, r) 27. if k = −1 then 28. PUSH(S, r) 29. else if r = u then 30. C ← SUBLIST(S, k, |S|)// C is a cycle 31. SSC ← SSC ∪ {C} 32. REMOVECYCLE(GSCC, C) 33. flag← true 34. end if 35. end if 36. end while 37. if flag=false then 38. DELETE(GSCC, u) 39. end if 40. end while 41. return SSC 42. end function Algorithms 2017, 10, 115 5 of 14

Algorithm 3. Delete a Vertex from a Weighted Digraph 1. Function DELETE(, )

2. for all 〈,〉 ∈ do

3. ←−{〈,〉} 4. ← −1 5. end for

6. for all 〈, 〉 ∈ do

7. ←−〈, 〉 8. ← −1 9. end for 10. ←−{} 11. end function

4.2. Cycle Detection

Proposition 2. Given a digraph ={,,,}, if {,,⋯,,} is a directed cycle, then these vertices belong to the same strongly connected components of .

This is the basis of step 2 of Algorithm 1. There are several efficient algorithms to calculate strongly connected components (SCCs) of a digraph, so we do not discuss the detail of step 2 of Algorithm 1. After SCCs are obtained, the cycles can be detected in each SCC. The cycle calculation is the core of Algorithm 1. Because the problem needs visit the vertices according their priorities, cycle should be detected using DFS. For large-scale graphs, the recursive DFS will cause out-of-memory exception, so we need an iterative version. The following data structures are adopted. Stack is used to store the visited sequence of vertices. Its interfaces include:

• PUSH(, ) to push into . • POP() to pop an element of . • PEEK() to return the top element of without popping out it. • SEARCH(, ) to return the index of in , and it returns −1 if is not in . • CLEAR() to clear the to empty. • SUBLIST(, , ) to return the sub-sequence of from index to (). • ISEMPTY() to return false if is not empty, and return true if is empty. Key-value pair table is applied to record each neighbor vertex of a visited vertex is visited or not. As shown in Figure 2, each key (, =1,2,⋯,) is a vertex that is unique in the whole table. Each has a list of values, and each value is either 0 or 1 representing the corresponding neighboring vertex of is unvisited or not. It has the following interfaces:

• CLEAR(, ) to reset all values of key to 0. • SUM(, ) to return the sum of values of key . The sum represents the number of neighboring vertices have been visited until now. • Algorithms GETF2017IRST, 10(,, 115 ) to return the first unvisited neighboring vertex of . 7 of 14 • SET(, , ) to set the value of neighboring vertex of to 1.

v1 0/1 0/1 0/1

v2

vn

keys values

Figure 2. An example of key-vale pair table.

When a cycle is detected, it should be removed at once using REMOVECYCLE (line 32) shown in Algorithm 5. The first for loop (lines 3–7) finds the cycle weight. The second for loop (lines 8–20) decreases all of the arc weights of C by wC. If the weight of an arc becomes 0, delete this arc (line 11). In further, if the in-degree or out-degree of a vertex becomes 0, delete this vertex (lines 13 and 16).

Algorithm 5. Remove a Cycle SCC SCC SCC SCC SCC SCC 1. Function REMOVECYCLE(G , C)//G = {V , E , W , P }, C = {v1, v2, ··· , vk} 2. wC ← wk,1 3. for i ← 1 to k − 1 do 4. if wi,i+1 < wC then 5. wC ← wi,i+1 6. end if 7. end for 8. for i ← 1 to k do 9. j ← 1 + (i mod k) 10. wi,j ← wi,j − wC 11. if wi,j = 0 then SCC SCC 12. E ← E − {vi, vj} out 13. if di = 0 then SCC 14. DELETE(G , vi) 15. end if in 16. if dj = 0 then SCC 17. DELETE(G , vj) 18. end if 19. end if 20. end for 21. end function

Proposition 3. Given a strongly connected component GSCC = {VSCC, ESCC, WSCC, PSCC}, Algorithm 4 can terminate with VSCC = Φ.

SCC Proof. Let u be the vertex with the highest priority in SCC G , i.e., pu is the minimal. From u, DFS is used to visit this SCC. Let v be the current visiting vertex. Case 1. v has no outgoing arc or all its neighbor vertices are visited in previous steps. In this case, out |Sum(T, v)| = dv , and v should be popped out from S. Case 1-1. If v = u, S becomes empty, so the inner while (line 18) exits and flag=false. This result means no cycle can be detected from u, so u is deleted (line 38). Case 1-2. If v 6= u, the inner while (line 18) goes on checking the top element of S. Case 2. v has at least one unvisited outgoing arc. In this case, we select one unvisited neighbor vertex r to continue searching. Algorithms 2017, 10, 115 8 of 14

Case 2-1. If r = u, a cycle C is detected (line 29). This cycle is removed by Algorithm 5. Because wC equals to at least one arc's weight, Algorithm 5 deletes at least one arc. Finally, flag=true, and the inner while loop exits. Case 2-2. If r is not visited, r is pushed into S and while loop continues. Case 2-3. If r is in stack but r 6= u, it continues finding the next vertex to visit. Note that Case 1-2, Case 2-2 and Case 2-3 will fall into Case 1-1 or Case 2-1 finally, so each iteration of outer while loop deletes an arc or vertex at least. Therefore, VSCC = Φ when Algorithm 4 finishes.

Remark 1. Algorithm 4 cannot detect all cycles of a given SCC, because a cycle may be broken when another one is removed.

4.3. Time Complexity Analysis

Let di, do be, respectively, the average in-degree and out-degree of vertices. In Algorithm 2, the for consumes O(|V| + |E|) to compute the in- and out-degree of all vertices. When no vertex can be deleted, the while only needs O(|V|) to scan all vertices. When only one vertex can be deleted in each iteration, it consumes O(|V|(di + do)). Algorithm 3 is very simple, whose time complexity is O(di + do). Let l be the length of cycle as the input of Algorithm 5. The first for consumes O(l). If only one arc can be deleted, the second for consumes O(l). In the worst case, l − 1 arcs of this cycle are all deleted, then the second for consumes O(l(di + do)). For function FUN(GSCC) of Algorithm 4, in the worst case, each iteration of the inner while detects a cycle, and each cycle only deletes one arc using Algorithm 5, so this function calls ( ESCC − 1) times

Algorithm 5. Obviously, the longest cycle is of length ESCC , and the shortest one is of length 2, so the average length of cycles is | SCC| 1 E ESCC + 2 i = . (4) | SCC| − ∑ E 1 i=2 2 N If G has N SCCs, each thread deals with K SCCs on average. Therefore, the worst time complexity SCC N |E |+2 is O( K × 2 × (di + do)). The time complexity of Algorithm 1 is the sum of Algorithms 2–4. In the worst case, the digraph has only one SCC, so its time complexity is O(|E|(di + do)).

4.4. An Example Taking Figure1 as an example, vertex 9 is deleted in first for its out-degree is 0, and its adjacent arcs are deleted too. Vertices 12, 11, and 8 are deleted in succession. After simplification, the remaining vertices are all in one SCC. Vertex 2 becomes the first one to find cycle due its highest priority. Starting from vertex 2, vertices 3, 4, 5 are visited successively. Between two adjacent vertices of 5, 6 is chosen as the next vertex due to its higher priority. After visiting 7, 10 and 5, a cycle (5, 6, 7, 10) is detected. Since it does not contain 2, so the algorithm backtracks and visits 1, and then visits 2 to detect a cycle {1, 2, 3, 4, 5}. This cycle’s weight wC = 9988. After calling Algorithm 3, the arc h3, 4i is deleted. Repeat the above process, cycles (5, 6, 7, 10) and (1, 4, 5) are detected and removed, and then the graph is cycle-free. In one word, Algorithm 4 can find 3 cycles in Figure1.

5. Experiments and Analysis The experiments are performed on a PC with Inter Core i7-5500U @ 2.40GHz CPU (dual-core), 6GB memory, Windows 7 operating system. The programs are coded with Java in Eclipse, and we set the upper-bound stack size to 4GB. The following versions of algorithm are compared: Algorithms 2017, 10, 115 9 of 14

• Recursion without simplification (RWOS). It detects cycle recursively without simplification. It is the popular algorithm used by many literatures. • Recursion with simplification (RWS). It detects cycle recursively after simplification. • Iteration without simplification (IWOS). It detects cycle iteratively without simplification. • Iteration with simplification (IWS). It detects cycle iteratively after simplification. Algorithms• Multi-thread 2017, 10, 115 parallel IWS (MPIWS). It detects cycle in parallel with IWS using multi-threads.9 of 14

TA In order to compare their performance, we define R = as the ratio of execution time between In order to compare their performance, we define =TB as the ratio of execution time between algorithm A (TA) and B (TB). Obviously, R < 1 means that algorithm A is better than B. Considering algorithm A ( ) and B ( ). Obviously, <1 means that algorithm A is better than B. Considering the algorithms to be compared, we define the algorithms to be compared, we define TIWOS TIWS TRWS TIWS TMPIWS R1== ;;R=2 = ;; =R3 = ; =; R4 = ; =; R5 = . .(5) (5) TRWOS TRWS TRWOS TIWOS TIWS

5.1. Experiments with Randomly Generated Digraphs First, we we generate generate 100 100 digraphs digraphs randomly randomly to analyze to analyze the performance the performance of the above of algorithms. the above algorithms.Each kind of Eachdigraph kind has of different digraph hasnumber different of vertices number and of arcs. vertices These and digraphs arcs. These have digraphs1000 × ( have = 10001, 2, ⋯× ,k 10)(k =vertices,1, 2, ··· and, 10 the) vertices, average andout thedegree average of vertices out degree is 1 to of 10 vertices in step isof 11. to For 10 each in step kind of of 1. Fordigraph, each kindwe generate of digraph, 10 different we generate digraphs, 10 different and each digraphs, algorithm and each runs algorithm 10 times for runs each 10 timesdigraph. for eachThe digraph.results are The average results over are averagethese 10 overruns. these 10 runs. As shown in Figure3 3,, thethe iterativeiterative algorithmalgorithm isis significantlysignificantly betterbetter thanthan recursiverecursive algorithmalgorithm because R1 <<11 andand R2<<11,, andandR 1 and andR 2decrease decrease while while the the number number of vertices of vertices increases. increases.R1 and andR2 are almost are almost the samethe same when when|V| is|| the is the same. same. When When|V ||=| =1000 1000, R, 1==0.657 0.657,, andand R2 = 0.6560.656.. When ||V|| ==10, 10,000 000,, R1 ==R2 ==0.290.29.. Figure3 3 also also showsshows thatthat simplificationsimplification cannotcannot reducereduce executionexecution time effectively.effectively. For aa differentdifferent numbernumber ofof vertices, vertices,R 3∈∈[ [0.975,0.9970.975, 0.997],, andand R4 ∈∈ [0.986,0.996][0.986, 0.996].. MPIWS outperforms IWS in further due to R5 ∈∈[ [0.378,0.558]0.378, 0.558]..

10000000

1000000

100000

10000

time/ms 1000

100

10

1 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 RWOS 6990.7 55364.6 144204.4 227650.2 527347.6 919228.2 2189464.8 2581142.1 3805896.5 5062995.7 RWS 6908.4 55182.2 143826.4 221878.1 525055.5 915965.9 2184367.5 2571125.7 3793553.7 5048193.8 IWOS 4598 31839.7 70271.8 103031.2 209388.7 329439 700322.6 836685.4 1158613.1 1468444.5 IWS 4532.8 31698.8 70019.7 102504.1 208101.9 327653.3 697668 832035.4 1153014.7 1461926.2 MPIWS 2423.7 17329.7 36060.1 33365.1 116100.1 187483.2 263369.7 432908 487033.4 630821.2 number of vertices Figure 3. ImpactsImpacts of number of vertices on execution time of each algorithm.

Figure 4 shows that the iterative algorithm outperforms the recursive version when the average Figure4 shows that the iterative algorithm outperforms the recursive version when the average degree of vertices is the same, and and decrease while the average out-degree of vertices degree of vertices is the same, and R1 and R2 decrease while the average out-degree of vertices increases. When out-degree is 1, = 0.881, = 0.981. When out-degree is 10, = 0.307, = increases. When out-degree is 1, R1 = 0.881, R2 = 0.981. When out-degree is 10, R1 = 0.307, 0.285. MPIWS also outperforms IWS in this figure, and ∈ [0.323,0.505]. R2 = 0.285. MPIWS also outperforms IWS in this figure, and R5 ∈ [0.323, 0.505]. Algorithms 2017, 10, 115 10 of 14 Algorithms 2017, 10, 115 10 of 14 10000000 Algorithms 2017, 10, 115 10 of 14 Algorithms 20171000000, 10, 115 10 of 14 10000000 10000010000000 1000000 100001000000 100000

time/ms 1000100000 10000 10010000

time/ms 1000

time/ms 101000 100 1100 10 12345678910 RWOS 10 3824.5 18442.9 120317.2 279947.2 590030 909380 1372129.8 1983661.8 3227007.8 7015543.6 1 RWS 1580.612345678910 12976.7 106660.1 269108.4 581993.4 904794 1369623.8 1982351.3 3226656.3 7550312.6 1 IWOSRWOS 3368.93824.512345678910 7900.7 18442.9 60892.8 120317.2 149765.7 279947.2 265845.6 590030 331567.7 909380 1372129.8 402258.3 1983661.8 595366.1 3227007.8 940202.7 7015543.6 2155465.5 IWSRWSRWOS 1550.81580.63824.5 5672.3 12976.718442.9 53983.4 106660.1120317.2 143901.9 269108.4279947.2 262251.1581993.4 590030 329881.3 904794909380 1369623.81372129.8 401484.7 1982351.31983661.8 594964.4 3226656.33227007.8 940090.2 7550312.67015543.6 2155374.8 MPIWSIWOSRWS 781.93368.91580.6 1829.3 12976.7 7900.7 20367.9 106660.1 60892.881995.3 149765.7269108.4 111850.1265845.6 581993.4 331567.7 134228.7 904794 1369623.8 402258.3 179865.1 1982351.3 595366.1 265354.1 3226656.3 940202.7 368891.4 2155465.57550312.6 652432 IWSIWOS 1550.83368.9 5672.37900.7 53983.460892.8 143901.9149765.7average 262251.1265845.6 out degree 329881.3331567.7 of vertices 401484.7402258.3 594964.4595366.1 940090.2940202.7 2155374.82155465.5 MPIWSIWS 1550.8781.9 1829.35672.3 20367.953983.4 143901.9 81995.3 111850.1262251.1 134228.7329881.3 179865.1401484.7 265354.1594964.4 368891.4940090.2 2155374.8 652432 FigureMPIWS 4. Impacts781.9 1829.3 of average 20367.9 degree 81995.3 ofaverage vertices 111850.1 out degree on 134228.7 of executionvertices 179865.1 time 265354.1 of each 368891.4 algorithm. 652432 average out degree of vertices FigureFigure 4. 4.Impacts Impacts of of average average degreedegree ofof vertices on on execution execution time time of of each each algorithm. algorithm. Figure 4 showsFigure 4. that Impacts simplification of average degree has muchof vertices effect on execution on the performanctime of each algorithm.e of these algorithms.

Figure Figure5 shows 4 showsthe numeric that simplification results of has and much ,ef fect and on the performancincrease rapidlye of these when algorithms. out-degree FigureFigure4 shows 4 shows that that simplification simplification has has much much effecteffect onon thethe performanceperformance of of these these algorithms. algorithms. increasesFigure 5from shows 1 to the 3, butnumeric they changeresults aof little andwhen out-degree, and is increaselarger than rapidly 3. Specially, when out-degree and FigureFigure5 shows 5 shows the numericthe numeric results results of R 3ofand Rand4, R 3and, R 4andincrease increase rapidly rapidly whenout-degree when out-degree increases equalincreases to or arefrom greater 1 to 3, thanbut they 1 when change the aaverage little when degr out-degreeee is 10, which is larger means than that 3. Specially, the simplification and has fromincreases 1 to 3, from but they 1 to change3, but they a little change when a little out-degree when out-degree is larger thanis larger 3. Specially, than 3. Specially,R3 and R 4 equal and to or noequal effect to on or the are algorithm’s greater than efficiency. 1 when the average degree is 10, which means that the simplification has arenoequal greater effect to or thanon are the 1greater algorithm’s when thethan average 1efficiency. when degreethe average is 10, degr whichee is means 10, which that means the simplification that the simplification has no effect has on theno algorithm’s effect on the efficiency. algorithm’s1.2 efficiency. 1.11.2 1.11.2 1 1.11 0.9 0.91 0.8 ratio 0.80.9

0.7ratio 0.70.8 0.6ratio 0.60.7 0.5 0.50.6 0.4 0.40.5 12345678910 12345678910 R30.4 0.4133 0.7036 0.8865 0.9613 0.9864 0.995 0.9982 0.9993 0.9999 1.0762 R3 0.413312345678910 0.7036 0.8865 0.9613 0.9864 0.995 0.9982 0.9993 0.9999 1.0762 R4 0.4603 0.7179 0.8865 0.9608 0.9865 0.9949 0.9981 0.9993 0.9999 1 R4R3 0.46030.4133 0.71790.7036 0.8865 0.96080.9613 0.98650.9864 0.9949 0.995 0.99810.9982 0.9993 0.9999 1.0762 1 avarege out-degree R4 0.4603 0.7179 0.8865 0.9608avarege 0.9865 out-degree 0.9949 0.9981 0.9993 0.9999 1 avarege out-degree FigureFigure 5. 5. 33 andand 44 under under differentdifferent out-degree. out-degree. Figure 5. and under different out-degree. Figure 5. R3 and R44under different out-degree. In Infact, fact, when when the the average average degree degree isis relativelyrelatively small, aa largelarge portion portion of of vertices vertices and and arcs arcs will will be be In fact, when the average degree is relatively small, a large portion of vertices and arcs will be deleteddeletedIn fact,by by Algorithm when Algorithm the average2, 2, as as shown shown degree in in Figure isFigure relatively 6. Wh small,en thethe a averageaverage large portion degree degree ofis is vertices1, 1, the the residual residual and arcs vertices vertices will be deleted by Algorithm 2, as shown in Figure 6. When the average degree is 1, the residual vertices deletedandand arcs arcs by are Algorithmare only only about about 2, as 0.7% 0.7% shown of of original inoriginal Figure graph.graph.6. When When the average thethe degreedegree degree is is 2, 2, is this 1,this theratio ratio residual increases increases vertices to to63% and63% and arcs are only about 0.7% of original graph. When the degree is 2, this ratio increases to 63% arcsrapidly.rapidly. are onlyOnly Only about less less than 0.7%than 10% of10% original of of vertices vertices graph. andand When arcsarcs can the be degreebe deleteddeleted is2, when when this ratiothe the average increasesaverage degree degree to 63% is islarger rapidly. larger rapidly. Only less than 10% of vertices and arcs can be deleted when the average degree is larger thanthan 3. 3. Onlythan less 3. than 10% of vertices and arcs can be deleted when the average degree is larger than 3.

1.201.20 1.20 1.00 1.00 1.00 0.80 0.80 0.80 0.60 0.60 0.60

residual ratios residual 0.40

residual ratios residual 0.40

residual ratios residual 0.40 0.20 0.200.20 0.00 12345678910 0.000.00 Residual vertex ratio 0.00711234567891012345678910 0.6285 0.8831 0.9614 0.9865 0.9950 0.9986 0.9994 0.9999 1.0000 ResidualResidual vertex edgevertex ratioratio ratio0.00710.00760.0071 0.6285 0.62730.6285 0.8831 0.88120.8831 0.96140.9613 0.9614 0.98620.9865 0.9950 0.9950 0.99870.9986 0.9986 0.9994 0.9994 0.9999 0.9999 1.0000 1.0000 ResidualResidual edge edge ratio ratio 0.00760.0076 0.6273 0.6273 0.8812 0.8812 0.9613 0.9613average 0.9862 out-degree 0.9950 0.9950 0.9987 0.9987 0.9994 0.9994 0.9999 0.9999 1.0000 1.0000 average out-degreeout-degree Figure 6. Ratio of number of residual vertices and arcs after simplification. FigureFigure 6. 6. Ratio Ratio of of number number of of residualresidual verticesvertices and and arcs arcs after after simplification. simplification.simplification. Algorithms 2017, 10, 115 11 of 14

5.2.Algorithms Experiments2017, with10, 115 SNAP Datasets 11 of 14 RWS, IWS, and MPIWS are used to detect and remove cycles of seven digraphs from SNAP datasets,5.2. Experiments and Table with2 shows SNAP the Datasets results. RWS cannot complete correctly for the last five graphs. The stack of RWS reaches 4GB before RWS can solve the problem, so it leads to out-of-memory exceptionRWS, in Java. IWS, IWS and and MPIWS MPIWS are can used solve to detect the problem and remove correctly, cycles but of MPIWS seven digraphs outperforms from IWS SNAP datasets, and Table2 shows the results. RWS cannot complete correctly for the last five graphs. The because <1. stack of RWS reaches 4GB before RWS can solve the problem, so it leads to out-of-memory exception in Java. IWSTable and 2. MPIWS Performance can solve Analysis the of problem Algorithms correctly, (time unit: but MPIWSms. ‘-‘ means outperforms it has no value). IWS because R5 < 1.

Graph p2p-Gnutella04Table 2. Performancep2p-Gnutella25 Analysisp2p-Gnutella30 of Algorithms p2p-Gnutella31 (time unit: ms.email-E ‘-‘ meansuAll itWeb-NotreDame has no value). Wiki-Talk Name

355.5179 615.3466 - - - - - Graph Name p2p-Gnutella04 p2p-Gnutella25 p2p-Gnutella30 p2p-Gnutella31 email-EuAll Web-NotreDame Wiki-Talk 315.4235 592.1235 1804.2942 2181.8719 4788.6087 6075.5061 7560.0935 TRWS 355.5179 615.3466 - - - - - 147.0574 342.7287 891.0342 1238.7748 2798.9455 3680.5876 4907.7557 TIWS 315.4235 592.1235 1804.2942 2181.8719 4788.6087 6075.5061 7560.0935 TMPIWS0.4662 147.05740.5788 342.72870.4938 891.03420.5678 1238.7748 0.5845 2798.9455 3680.58760.6058 4907.75570.6492 R5 0.4662 0.5788 0.4938 0.5678 0.5845 0.6058 0.6492 5.3. Experiments with Real Dept Graphs 5.3. Experiments with Real Dept Graphs In order to analyze the performance in real application, we utilize them for a real debt graph. The debtIn data order comes to analyze from Qingdao the performance YouRong inDevelo real application,pment Co., Ltd., we utilize in Shandong them for Province, a real debt China. graph. ThisThe graph debt has data 7692 comes vertices from and Qingdao 8737 YouRongarcs, so the Development average out-degree Co., Ltd., of in each Shandong vertex is Province, about 1.14. China. AfterThis simplification, graph has 7692 the vertices graph andonly 8737 has arcs,184 sovertic thees average and 345 out-degree arcs, namely of each only vertex 2.39% is aboutvertices 1.14. and After 3.95%simplification, arcs are saved the graphafter simplification. only has 184 vertices The simplified and 345 arcs, graph namely is shown only in 2.39% Figure vertices 7. This and figure 3.95% is arcs drawnare savedby Pajek. after simplification. The simplified graph is shown in Figure7. This figure is drawn by Pajek.

FigureFigure 7. A 7. realAreal debt debt graph graph after after simplification. simplification.

Figure 8 presents the execution times of RWOS, RWS, IWOS, IWS, and MPIWS to solve the real Figure8 presents the execution times of RWOS, RWS, IWOS, IWS, and MPIWS to solve the debt graph. We can see that = 0.467, = 0.456, = 0.663, = 0.647, = 0.452, which real debt graph. We can see that R1 = 0.467, R2 = 0.456, R3 = 0.663, R4 = 0.647, R5 = 0.452, shows simplification, iteration, and parallelism improves the performance when compared with which shows simplification, iteration, and parallelism improves the performance when compared with traditional recursive algorithms without simplification. traditional recursive algorithms without simplification. Algorithms 2017, 10, 115 12 of 14 Algorithms 2017, 10, 115 12 of 14 Algorithms 2017, 10, 115 12 of 14 20000 20000 18060.25 18000 18060.25 18000 16000 16000 14000 14000 11968.45 12000 11968.45 12000 10000 8440.9 10000 8000 8440.9 8000 5461.95 execution time/ms execution 6000 5461.95

execution time/ms execution 6000 4000 2466.71 4000 2000 2466.71 2000 0 0 RWOS RWS IWOS IWS MPIWS RWOS RWS IWOS IWS MPIWS algorithms algorithms Figure 8. Execution time of four algorithms. Figure 8. Execution time of four algorithms. 5.4. Performance Comparisons on Different Computers 5.4.5.4. Performance ComparisonsComparisons on Different ComputersComputers We compare the speedups of IWS and MPIWS on the follow CPUs: Intel Core i7-7700 WeWe comparecompare the the speedups speedups of IWS of andIWS MPIWS and MPIWS on the followon the CPUs: follow Intel CPUs: Core i7-7700Intel Core (quad-cores), i7-7700 (quad-cores), Intel Core i7-5820K (six-cores), and the results are shown in Figure 9. The main Intel(quad-cores), Core i7-5820K Intel (six-cores),Core i7-5820K and the(six-cores), results areand shown the results in Figure are9 .shown The main in memoryFigure 9. is The still 6GB.main memory is still 6GB. Since RWS still cannot solve all graphs, we only compare IWS and MPIWS. In Sincememory RWS is still still 6GB. cannot Since solve RWS all still graphs, cannot we solve only all compare graphs, IWSwe only and compare MPIWS. IWS In Figure and MPIWS.9, IWS-2, In Figure 9, IWS-2, IWS-4, and IWS-6 are the execution time of IWS on i7-5500U, i7-7700, and i7-5820K, IWS-4,Figure 9, and IWS-2, IWS-6 IWS-4, are the and execution IWS-6 are time the executio of IWS onn time i7-5500U, of IWS i7-7700,on i7-5500U, and i7-5820K,i7-7700, and respectively. i7-5820K, respectively. MPIWS-2, MPIWS-4, and MPIWS-6 are the execution time of MPIWS on i7-5500U, MPIWS-2,respectively. MPIWS-4, MPIWS-2, and MPIWS-4, MPIWS-6 and are MPIWS-6 the execution are the time execution of MPIWS time on of i7-5500U, MPIWS on i7-7700, i7-5500U, and i7-7700, and i7-5820K, respectively. The “debt-graph” is the graph used in Section 5.3. i7-5820K,i7-7700, and respectively. i7-5820K, respectively. The “debt-graph” The “debt-graph” is the graph used is the in graph Section used 5.3 .in Section 5.3.

Figure 9. Execution time of different algorithms on different CPU. Figure 9. Execution time of different algorithms on different CPU. Figure 9. Execution time of different algorithms on different CPU. Figure 9 shows that the increasement of cores has little influence on IWS. However, MPIWS Figure 9 shows that the increasement of cores has little influence on IWS. However, MPIWS changes a lot using different CPU. TMPIWS using i7-7700 is about 59.1~66.3% of TMPIWS using i7-5500U, changesFigure a lot9 showsusing different that the increasementCPU. TMPIWS using of cores i7-7700 has is little about influence 59.1~66.3% on IWS.of TMPIWS However, using i7-5500U, MPIWS and TMPIWS using i7-5820K is about 41.1~67.4% of TMPIWS using i7-7700. This figure also shows that R5 changesand TMPIWS a lot using using i7-5820K different is CPU. aboutT MPIWS41.1~67.4%using of i7-7700 TMPIWS is using about i7-7700. 59.1~66.3% This offigureTMPIWS alsousing shows i7-5500U, that R5 decreases with an increase of cores. Using i7-5500U, i7-7700, and i7-5820K, the values of R5 are, anddecreasesTMPIWS withusing an i7-5820K increase isof about cores. 41.1~67.4% Using i7-5500U, of TMPIWS i7-7700,using and i7-7700. i7-5820K, This figurethe values also shows of R5 thatare, respectively, ∈ [0.4516,0.6492], ∈ [0.2705,0.3885], and ∈ [0.1208,0.2685]. Rrespectively,5 decreases with ∈ an [0.4516,0.6492] increase of cores., ∈ Using [0.2705,0.3885] i7-5500U,, i7-7700, and and∈ [0.1208,0.2685] i7-5820K, the. values of R5 are, respectively,6. ConclusionR 5and∈ [ 0.4516,Discussion 0.6492 ], R5 ∈ [0.2705, 0.3885], and R5 ∈ [0.1208, 0.2685]. 6. Conclusion and Discussion Many real-world scenarios and applications can be modeled as a graph, and many problems Many real-world scenarios and applications can be modeled as a graph, and many problems need to detect cycles. Derived from cycle detection and removal problem in debt graph, this paper need to detect cycles. Derived from cycle detection and removal problem in debt graph, this paper defines a new problem that detects cycle according to the vertex priority, and removes cycles defines a new problem that detects cycle according to the vertex priority, and removes cycles Algorithms 2017, 10, 115 13 of 14

6. Conclusion and Discussion Many real-world scenarios and applications can be modeled as a graph, and many problems need to detect cycles. Derived from cycle detection and removal problem in debt graph, this paper defines a new problem that detects cycle according to the vertex priority, and removes cycles according to arc weight. A multi-threading parallel and iterative algorithm is proposed to solve this problem. Iteration is applied to replace recursion and to avoid out-of-memory exception, and multi-thread is applied to improve the efficiency. The experiments exhibit that the iterative algorithm can be run on a single commodity PC to solve the large-scale graph, and parallel algorithm outperforms sequential algorithm obviously. In further, the proposed algorithm uses simplification to reduce the scale of graph. The experiments show that the execution efficiency is improved significantly by simplification when there are many vertices having 0 in- or out-degree. Generally, iteration outperforms recursion while solving a same problem, but simplification is only applicable to sparse graph. If the graph is not sparse, line 2 of Algorithm 1 can be deleted. Moreover, commodity PCs cannot solve the problem, even use of MPIWS in case of the graph is too large, so parallel algorithms depending on computer cluster must be applied, such as the algorithms proposed in [14,21,22].

Acknowledgments: This work is supported by the National Key Research and Development Program of China Grant No. 2017YFC0804406 and 2017YFB0202001, and the Open Project of Shandong Provincial Key Laboratory of Computer Networks, Grant No. SDKLCN-2015-03. Author Contributions: H. Cui conceived and designed the experiments; J. Niu performed the experiments; C. Zhou and M. Shu analyzed the data; H. Cui wrote the paper. Conflicts of Interest: The authors declare no conflict of interest.

References

1. Kühn, D.; Osthus, D. A survey on hamilton cycles in directed graphs. Eur. J. Combin. 2012, 33, 750–766. [CrossRef] 2. Silva, J.L.C.; Rocha, L.; Silva, B.C.H. A new algorithm for finding all tours and hamiltonian circuits in graphs. IEEE Lat. Am. Trans. 2016, 14, 831–836. [CrossRef] 3. Lv, X.; Zhu, D. An approximation algorithm for the shortest cycle in an undirected unweighted graph. In Proceedings of the International Conference on Computer, Mechatronics, Control and Electronic Engineering, Changchun, China, 24–26 August 2010; IEEE: New York, NY, USA, 2010; pp. 297–300. 4. Yuster, R. A shortest cycle for each vertex of a graph. Inform. Process. Lett. 2011, 111, 1057–1061. [CrossRef] 5. Paulusma, D.; Yoshimoto, K. Cycles through specified vertices in triangle-free graphs. Discuss. Math. Gr. Theory 2007, 27, 179–191. [CrossRef] 6. Li, B.; Zhang, S. Heavy subgraph conditions for longest cycles to be heavy in graphs. Discuss. Math. Gr. Theory 2016, 36, 383–392. [CrossRef] 7. Li, B.; Xiong, L.; Yin, J. Large degree vertices in longest cycles of graphs, I. Discuss. Math. Gr. Theory 2016, 36, 363–382. [CrossRef] 8. Gerbner, D.; Keszegh, B.; Palmer, C.; Patkos, B. On the Number of Cycles in a Graph with Restricted Cycle Lengths. Available online: https://arxiv.org/abs/1610.03476 (accessed on 9 October 2017). 9. Sankar, K.A.; Sarad, V. A time and memory efficient way to enumerate cycles in a graph. In Proceedings of the International Conference on Intelligent and Advanced Systems, Kuala Lumpur, Malaysia, 25–28 November 2007; IEEE: New York, NY, USA, 2007; pp. 498–500. 10. Haeupler, B.; Kavitha, T.; Mathew, R.; Sen, S.; Tarjan, R.E. Incremental Cycle Detection, Topological Ordering, and Strong Component Maintenance. Available online: https://arxiv.org/abs/1105.2397 (accessed on 9 October 2017). 11. Bender, M.A.; Fineman, J.T.; Gilbert, S.; Tarjan, R.E. A new approach to incremental cycle detection and related problems. ACM Trans. Algorithms 2016, 12.[CrossRef] 12. Reif, J.H. Depth-first search is inherently sequential. Inform. Process. Lett. 1985, 20, 229–234. [CrossRef] Algorithms 2017, 10, 115 14 of 14

13. Karimi, M.; Banihashemi, A.H. Message-passing algorithms for counting short cycles in a graph. IEEE Trans. Commun. 2013, 61, 485–495. [CrossRef] 14. Rocha, R.C.; Thatte, B.D. Distributed cycle detection in large-scale sparse graphs. In Proceedings of the Simpósio Brasileiro de Pesquisa Operacional, Pernambuco, Brazil, 25–28 August 2015; XLVII SBPO: Pernambuco, Brazil, 2015; pp. 1–11. 15. Malewicz, G.; Austern, M.H.; Bik, A.J.C.; Dehnert, J.C.; Horn, I.; Leiser, N.; Czajkowski, G. Pregel: A system for large-scale graph processing. In Proceedings of the ACM SIGMOD International Conference on Management of Data, Indianapolis, IN, USA, 6–11 June 2010; ACM: New York, NY, USA, 2010; pp. 135–146. 16. Gonzalez, J.E.; Xin, R.S.; Dave, A.; Crankshaw, D.; Franklin, M.J.; Stoica, I. GraphX: Graph processing in a distributed dataflow framework. In Proceedings of the 11th USENIX Symposium on Operating Systems Design and Implementation, Broomfield, CO, USA, 6–8 October 2014; USENIX: Berkeley, CA, USA, 2014; pp. 599–613. 17. Salihoglu, S.; Widom, J. GPS: A graph processing system. In Proceedings of the 25th International Conference on Scientific and Statistical Management, Baltimore, MD, USA, 29–31 July 2013; ACM: New York, NY, USA, 2013; pp. 1–31. 18. Féray, V. Weighted dependency graphs. Available online: https://arxiv.org/abs/1605.03836 (accessed on 9 October 2017). 19. McLendon, W.; Hendrickson, B.; Plimpton, S.J.; Rauchwerger, L. Finding strongly connected components in distributed graphs. J. Parallel Distrib. Comput. 2005, 65, 901–910. [CrossRef] 20. Leskovec, J.; Sosic, R. SNAP: A general-purpose network analysis and graph-mining library. ACM Trans. Intell. Syst. Technol. 2016, 8.[CrossRef][PubMed] 21. Seidl, T.; Boden, B.; Fries, S. CC-MR—Finding connected components in huge graphs with MapReduce. In Proceedings of the Joint European Conference on Machine Learning and Knowledge Discovery in , Bristol, UK, 24–28 September 2012; Springer: Berlin/Heidelberg, Germany, 2014; pp. 458–473. 22. Slota, G.M.; Rajamanickam, S.; Madduri, K. BFS and coloring-based parallel algorithms for strongly connected components and related problems. In Proceedings of the IEEE 28th International Parallel and Distributed Processing Symposium, Phoenix, AZ, USA, 19–23 May 2014; IEEE: New York, NY, USA, 2014; pp. 550–559.

© 2017 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).