You are not logged in. Please login at www.codechef.com to post your questions!

×

Does stack limit in c is higher than stack limit in java?

I was solving one problem on codechef and I used recursion, when I am submitted it's solution in c and it was a successful submission. But when I tried to do it in java I got NZEC error. does it mean c has higher stack limit for executing recursive calls than java.

asked 24 Feb '16, 18:18

arpit728's gravatar image

1★arpit728
6831765
accept rate: 10%


This problem is faced by many coder/programmers. Stack limit as answered above is smaller and can be increased. For more detail visit This .

link

answered 16 Jul '16, 13:05

atulag's gravatar image

4★atulag
1062
accept rate: 12%

Your Question should be treated as compiler and OS specific.

The Standard (language) does'n mandate the min/max stack size and doesn't specifies the location of the stack memory.

link

answered 31 Mar '16, 03:31

tara24's gravatar image

0★tara24
261
accept rate: 16%

edited 31 Mar '16, 03:33

Yes Stack limit in Java is less than that of C. I also faced some problems initially. Anyways you can increase the stack limit in Java by using multi-threading. Create thread for each recursion which will have it own stack limit.
Here is code snippet to create the thread

new Thread(null, new Runnable() {
            public void run() {
                try {
                    new ClassName().functionName();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (StackOverflowError e) {
                    System.out.println("RTE");
                }
            }
        }, "1", 1 << 26).start();

Write the above code snippet in main Function. You can see the sample solution here

link

answered 24 Feb '16, 23:11

ankurverma1994's gravatar image

4★ankurverma1994
415114
accept rate: 8%

@ankurverma1994

does this technique compromises the performance??

(24 Feb '16, 23:13) arpit7281★

@ankurverma1994

That link is not accessible to me, It says "403 Access denied".

(24 Feb '16, 23:16) arpit7281★

No it doesn't compromise with the performance.You can view any of my recent submission. Here is other sample solution.

(24 Feb '16, 23:31) ankurverma19944★
(25 Feb '16, 00:31) arpit7281★

If this answers your question then mark it as accepted and close the question.

(25 Feb '16, 00:36) ankurverma19944★

@ankurverma1994

Isn't there any limit to number of threads that can execute simultaneously??

(25 Feb '16, 08:53) arpit7281★

There is limit to create the number of threads. I don't know exactly how much. You can google it to learn more about it. The code snippet that I gave you, will not give StackOverflowError in Competitive Programming if your algorithm is correct.

(25 Feb '16, 11:55) ankurverma19944★
showing 5 of 7 show all

Very good answer link here for What are the various reasons that can cause NZEC error on online coding platforms?

link

answered 24 Feb '16, 18:39

mil213's gravatar image

0★mil213
182
accept rate: 33%

Can you provide link to Java code?

link

answered 24 Feb '16, 18:26

abhiroj786's gravatar image

2★abhiroj786
8111
accept rate: 22%

@abhiroj786

https://www.codechef.com/viewsolution/9476321

see function which is named as

findSet(int a)

(24 Feb '16, 18:35) arpit7281★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,657
×1,477
×1,404
×1,302
×348
×173

question asked: 24 Feb '16, 18:18

question was seen: 1,717 times

last updated: 16 Jul '16, 13:05