C # program Data volume is too large to cause stack overflow stack Overflow by the big data

Source: Internet
Author: User

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
     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 )

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: