The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
0 votes
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
In heap we cannot practically create activation records as we cannot guess the size of it. But stack does it for us.
So what is the answer? No support for recursion using heaps?
Yes @sripo
please add the test series name on the top
Think it is Made Easy or the one who shall not be named one of them don't remember exactly.

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
A Heap can be implemented as a stack thereby making heap recursive.That is my doubt.
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
Doubt cleared.
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
66,665 users