473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

chance of stack overflow

we kno during call of a subroutine, the address of next
instruction( from which the execution is supposed to start after the
subroutine is executed ) is stored in stack. in case of recursion
(e.g. we are sorting an array having length one million using heap
sort), we have to call a particular subroutine thousands time. Is
their any chance of stack overflow ?? if yes how can we avoid ??

here we have no choice other than subroutine..
Dec 2 '07 #1
4 1711
asit said:
we kno during call of a subroutine, the address of next
instruction( from which the execution is supposed to start after the
subroutine is executed ) is stored in stack.
We don't actually know that, because the C Standard doesn't guarantee it,
but it is certainly true that some systems work in that way.
in case of recursion
(e.g. we are sorting an array having length one million using heap
sort), we have to call a particular subroutine thousands time. Is
their any chance of stack overflow ??
It's unlikely. If you're sorting a million items in a recursive O(n log n)
algorithm, you're unlikely to have to recurse more than twenty calls deep,
and that's really no big deal. (2^20 == 1048576)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 2 '07 #2
then what is the best recursion procedure..if we have to sort a
million integers
Dec 2 '07 #3
asit said:
then what is the best recursion procedure..if we have to sort a
million integers
It depends on the range of the integers. For example, if the inputs were
all in the range 0 to 9 - single digits - I would give one answer, and if
the inputs were bignums of arbitrary length, I'd give a very different
answer. And if, as is likely, the truth is somewhere between those two
outliers, I'd give a different answer again.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 2 '07 #4
asit wrote:
we kno during call of a subroutine, the address of next
instruction( from which the execution is supposed to start after the
subroutine is executed ) is stored in stack.
We know (note spelling) no such thing. There are many ways for
subroutines to be supplied with the location to which returns should
lead, and many ways for subroutines to use such information.

Any question based upon your false premise is useless. However,
in case of recursion
(e.g. we are sorting an array having length one million using heap
sort), we have to call a particular subroutine thousands time. Is
their any chance of stack overflow ?? if yes how can we avoid ??
Unless you somehow have access to an infinite memory machine, it is
obvious that any unrestrained use of a stack carries with it the chance
of overflowing that stack. It doesn't matter what use you put that
stack to. There is no automatic way of avoiding violating the limits of
any region of memory. As to which precautions you should take, that
is obviously intimately bound to your implementation. Knowledge of your
implementation and the skills to use that knowledge have nothing to do
with the C programming language and are off-topic in <news:comp.lang.c>

Dec 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ip4ram | last post by:
I am quite puzzled by the stack overflow which I am encountering.Here is the pseudocode //define stack structure //function operating on stack void my_stack_function( function parameters) {...
7
by: Aguilar, James | last post by:
Hello all, To begin, yes, this -is- a homework assignment. However, it is for my Algorithms class, and my instructor has given us explicit permission to use "expert" groups like newsgroups, so...
19
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
4
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. ...
2
by: David W. Walker | last post by:
I am attempting to port a C code that runs OK on a number of Linux and Unix machines to Windows XP using Visual Studio C++. I have set the program up as a console application, but when I try to run...
6
by: Daz | last post by:
Hi everyone! It is indeed, once again time for me to ask another stupid question. I have been searching around on the net for quite a while, and can't find anything that explains 'exactly'...
24
by: John | last post by:
I know this is a very fundamental question. I am still quite confused if the program call stack stack should always grows upwards from the bottom, or the opposite, or doesn't matter?? That means...
7
by: amit.atray | last post by:
Environement : Sun OS + gnu tools + sun studio (dbx etc) having some Old C-Code (ansi + KR Style) and code inspection shows some big size variable (auto) allocated (on stack) say for ex. char...
87
by: CJ | last post by:
Hello: We know that C programs are often vulnerable to buffer overflows which overwrite the stack. But my question is: Why does C insist on storing local variables on the stack in the first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.