The Gateway to Computer Science Excellence
+1 vote
185 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
in Compiler Design by Active (2.4k points) | 185 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.
by Boss (10.3k 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
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
50,645 questions
56,562 answers
195,730 comments
101,646 users