The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
103 views
Does Heap Allocation support both recursion and dynamic memory allocation? Because,a stack can be implemented using dynamic memory allocation.Please correct me.

Test Series answer shows only dynamic memory allocation
asked in Compiler Design by Active (1.3k points) | 103 views
0
In heap we cannot practically create activation records as we cannot guess the size of it. But stack does it for us.
0
So what is the answer? No support for recursion using heaps?
0
Yes @sripo
0
please add the test series name on the top
0
Think it is Made Easy or the one who shall not be named one of them don't remember exactly.
0

https://gateoverflow.in/2052/gate2014-3-18 

Refer Arjun sir's reply on the above link. Might be of help

1 Answer

+1 vote
Best answer
Heap support dynamic allocation but not recursion

because recursion need stack structure

now one thing more

If you are willing to convert your recursion to iteration, then it is possible to use only heap space, but that isn't really recursion. You would do so by implementing a stack in the heap.
answered by Loyal (7.7k points)
selected by
0
A Heap can be implemented as a stack thereby making heap recursive.That is my doubt.
+1
heap is the reserve  area in the PCB where the dynamic allocation can take palce . now come to the point ,in this area we can simulate the stack (think as we can make the stack ) and the recursive process can take place in that stack .
now the concluson is that  heap is the area in which we made  the stack ,so the recursion property is not support by the heap itself it is support by the stack made in the heap area
0
Doubt cleared.
+1
Thanks a lot

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

47,001 questions
51,321 answers
177,477 comments
66,665 users