There are many useful generics in C #, but in the case of large amount of data (M), many times the program will appear in the small test data run correctly, replaced by actual data, there is stack overflow, in the case of not optimizing the program, if the results of the experiment.
In C # Two methods can solve this problem, this time in the direction of the map to find strong connected branches as an example. The depth-first search strategy is used when computing strongly connected branches.
A recursive implementation of DFS is the primary cause of stack overflow and is implemented using a separate thread, because the maximum size of the stack can be customized in C #, such as: Using the 1024000000 Index to implement DFS the first method is implemented as follows:
var T = new Thread (delegate () {dfs_loops (adj_list, rev_adj_list);}, 1073741824); T.start ();
The use of threads can refer to: A simple example of C # multithreading synchronization
The pseudo code for the second method is as follows:
For the vertices start from N to 1
v = Take the vertex
if V is explored then continue (go to For loop)
creat e New Stack Coll
push v into the stack coll while
(stackcol.count>0)
w = Peek item from stack col (Make Sur e don ' t pop here in this stage)
Markexplore (w)
push only one unexplored adjacent node into the stack Col
cont Inue; (Go to While loop)
If there is no adjacent node
POPs item from the Stack coll (remember we just peek the item earlier, didn ' t pop it )