What is the maximum number of statements may be recursive calls?

2009-11-08 4:38 am
I want to know more about recursive calls since this topic is going to be in the coming final test.

I want to ask, in a single function declaration, what is the maximum number of statement that may be recursive calls? ( Since I am not too sure the meaning of a single function declaration, I assumed it is a function that has only 1 variable in parameter. I don't know about the answer should be "there is no fixed maximum" or "n, where n is the argument", but I think we can write as many as recursive calls as we want) Please correct me if I am wrong

and the maximum depth of recursive calls may make? ( This one I think it is no fixed maximum, except the memory stack runs out. But if I am wrong, please correct me)


Thank you so much, I read through the chapter of my book already, but couldn't find something related to this question

回答 (4)

2009-11-08 5:06 am
✔ 最佳答案
I just answered a similar question though the answer will be different here.

You are correct that recursive functions are limited by stack space. However, for some interpreted languages such as BASIC, Java and others, your recursive limit or call limit may be much smaller since it is limited to the interpreter's memory space or perhaps it's design limit.

As an example, some of the old versions of BASIC were limited to only about 15 calls before running out of "call" space. Some didn't really use a stack and were actually limited by a hard coded design limit.They simply stopped with an error if the number was exceeded.

I ran a simple recursive program recently using C. It actually had no problems at a depth of over 100 so there the likely limit was actually available stack space which could vary depending on how the program was compiled, which microprocessor it was compiled for and how much memory was available.

So, there are 2 different examples of recursive limits and one can be quite variable. One of them will be correct on your test. I'm afraid the only correct answer will be one found in your book somewhere. In school you have to regurgitate the stuff that they teach you. Not the stuff in the real world.

Shadow wolf
2009-11-08 12:51 pm
You can have as many recursive calls as your resources (memory, etc) will allow.
2009-11-08 12:49 pm
This will depend on the implementation.

Conceptually there should be no limit, but in practice it is limited by (for example) available memory. If allowed to extend to disk pages, it could be a very large number, but at the expense of performance.

So: This is going to depend on the implementation.
2009-11-08 12:48 pm
Questions are a bit hard to understand, but I think you have the right answers.

One function can make as many recursive calls as it wants. The value of an argument n would have no effect.

Most languages today don't place a maximum depth on recursive calls, but you are right: Each call consumes stack space, so at some point you will run out and get an error. How many calls it takes to do that will depend on the code, the compiler and the operatating system.


收錄日期: 2021-05-01 09:35:22
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20091107203824AA2wiJ4

檢視 Wayback Machine 備份