baynezy
baynezy

Reputation: 7046

System.StackOverflowException too much recursion

I am doing an Algorithm class and I am building an implementation of Kosaraju's algorithm as part of the homework.

I have several small datasets where the algorithm is returning the correct results and performing fine. However, when I attempt my homework assignment which has 5,105,043 edges and 875,714 nodes in it I am getting a System.StackOverflowException which seems to be because there is too much recursion.

However, this recursion is required to solve the question. So what I am asking is there a way to configure .Net to allow more recursion?

Upvotes: 0

Views: 2008

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564403

So what I am asking is there a way to configure .Net to allow more recursion?

The recursion limit is based on the stack size allocated for the current thread. This can be changed via editbin /stack for the program, or edited for a specific thread upon the thread's construction.

That being said, any recursive algorithm can be switched to using a stack instead. This would likely prove more maintainable over time, as it would no longer be dependent on having a very large stack to process appropriately.

Upvotes: 3

Related Questions