Relative Content

Tag Archive for heap

Stack and heap – dynamic allocation question

Sources usually mention that dynamically created variables are allocated on the heap, while functions’ variables on the stack. Also the ones on the stack cease to exist automatically when e.g. the function which contains the variable exits. If I understand correctly, data fields of class are on the heap.
I do not understand, what is meant by ‘dynamic’? As I see it, when the code is running, anything being created is created dynamically on the fly, be it function variables or objects with variables inside them. I would be glad for simple explanation. Thanks

find second smallest element in Fibonacci Heap

I need to describe an algorithm that finds the second smallest element in a Fibonacci-Heap using the Operations: Insert, ExtractMin, DecreaseKey and GetMin. The last one is an algorithm previously implemented to find and return the smallest element of the heap.

Marked nodes in Fibonacci heaps

I don’t understand why Fibonacci heaps have marked nodes (picture).
A node is marked when its child is deleted. Quoting from Wikipedia: “[Keeping degree of each node low] is achieved by the rule that we can cut at most one child of each non-root node. When a second child is cut, the node itself needs to be cut from its parent and becomes the root of a new tree.”

Heap overflow vs stack overflow

So as a general rule to avoid a stack overflow, big objects should be allocated to the heap (correct me if I am wrong). But, since the heap and the stack expand towards each other, wouldn’t this cause heap overflow or alternatively limit the space for the stack and higher the chances of stack overflow?