Questions tagged [heap]

A heap (data structure) is a tree that is ordered with respect to depth. Heap can also refer to process memory set aside for dynamic allocation.

1
vote
0answers
19 views

Reason why I am having garbage values appear?

So when I call this function for a value in my array, it prints out a garbage value then on the next line what I actually want to print. When I enter a value not in the array it errors out. I am new ...
1
vote
0answers
24 views

Windbg memory size in heap summary did not match the usage statistic

I have a .dmp file, created from TaskManager. When using windbg command: !heap -s it shows result like this: In this line: 00a40000 00000002 1084772 1074756 1084772 339109 3979 218 4 ...
1
vote
0answers
22 views

how to implement level order print for MaxHeap

I'm currently making a MaxHeap program and I need to print my heap in level order. How can this be done? Do I create a method to print the heap in level order inside of my heap class or would I do it ...
0
votes
2answers
19 views

Need Help Counting number of swaps in a MaxHeap

I'm currently working on a project where I have to create a max heap. I'm currently using my textbooks version of the heap which somewhat looks like: public MaxHeap(int initialCapacity) { if (...
0
votes
0answers
23 views

Multithreaded heap sort algorithm

Implement a multithreaded program to sort sufficiently big data using heap sort algorithm. The data to be read from File. Also, show that multithreaded version of the program is faster than the serial ...
1
vote
1answer
27 views

Height of heap with n elements

I am having the following question: "The height of a tree is the length of the longest branch of the tree. From the definition of height, what is the height of a heap with n elements? Give a clear ...
0
votes
1answer
38 views

Are generator function's local variable stored on Stack or Heap?

In this article: https://wingolog.org/archives/2013/06/11/ecmascript-generators-from-a-performance-perspective, it mentioned that: In a generator function, V8 stores local variables on the heap ...
-1
votes
0answers
18 views

How can I get a hold of the stack and heap of code I wrote?

My question is straight forward, How do I get the stack and heap of C# code? The programs are really small, like 20 lines max and usually 10+- lines long. Is there a program where you can run your ...
-1
votes
0answers
29 views

Java out of memory heap space error with A* search algorithm?

I'm making a program that solves an 8 puzzle with the a* search algorithm. It works for most inputs, however when I try to put in the pattern that takes the most amount of moves to solve (31) 8 6 7 ...
1
vote
1answer
45 views

How to use compareTo with T Java generic?

I am trying to use compareTo with Java generic, but it keeps giving me an error. I then implemented public interface Comparable<T> { int compareTo(T o); } But still did not help. The ...
1
vote
1answer
43 views

Why is the following code susceptible to heap overflow attack

I'm new to cyber security, and I am trying to understand why the following code is susceptible to a heap overflow attack... struct data { char name[128]; }; struct fp { int (*fp)(); }; void ...
2
votes
0answers
64 views

Why there is no max heap data type in Python Standard Library?

I have read the topic What do I use for a max-heap implementation in Python? that has been viewed more than 74k times as of today (meaning that many people came across the same issue) and I've been ...
-1
votes
0answers
46 views

HeapSort algorithm

I'm still trying to learn how data structures work. Can you check the heapRebuild, HeapSort method. I'm always getting error. this is the given: import java.util.*; public class HeapSort<T> { ...
0
votes
0answers
8 views

Any way to validate a pointer before attempting to free it?

One of the more ugly runtime errors occurs when one attempts to free an invalid pointer, like a null pointer. Of course, one can check that a pointer is not null before attempting to free it, but ...
0
votes
1answer
28 views

C++ Error when Initializing a pointer to a pointer

I am using a large code-base, so forgive me for not including all source code. I will summarize the problem as best I can and hopefully it is enough to give some intuition into an answer. When ...
-1
votes
0answers
12 views

How does return value in a function pass from stack to heap?

I am always confused about the memory allocation, here's one of the case. People say that the stack is for value types in the scope, when out of scope, the values are popped. If this is the case, ...
0
votes
0answers
30 views

How to lessen memory usage when using many ArraysLists in Java

I'm making a program to play Misere Nim, and I'm running into some problems with memory. I use ArrayLists to hold the possible moves that could be done, and this is causing an OutOfMemory exception. ...
-1
votes
1answer
30 views

Reassigning Parent Nodes and Child Nodes in Changing Binary Tree to Heap

I am working on a homework assignment for my class and I am trying to change a balanced binary tree into a heap using code that the professor provided. His basic instructions were to create a method ...
1
vote
1answer
49 views

C++ Heap Corruption Detected While Deleting Array

I've been getting a Heap Corruption error in the pop() function of a DynamicStack i've been trying to make. Right now i've set it so that if the number of items is less than around 1/4 of the ...
0
votes
2answers
61 views

Kth smallest in stream of numbers

We are given a stream of numbers and Q queries. At each query, we are given a number k. We need to find the kth smallest number at that point of the stream. How to approach this problem? total size ...
0
votes
0answers
70 views

How do we show that a ternary max heap has a worst case complexity of 0(log n ) , where n is the length of the array

Ternary Max Heap size(3 children). Is the size of the child tree also 2n/3 ? If we have 3 children, how do we get a half full situation? In CLRS, third Edition, on page 155, it is given that in ...
2
votes
1answer
47 views

Why doesn't strsep() work with pointers to the stack?

It appears that there is a pointer compatibility problem using the function strsep to find the first word of a string. So far I always thought that char *s and char s[] are completely interchangeable. ...
-1
votes
0answers
33 views

Possible efficient approach other than heap based solution

Suppose we are given an array A where each element represents a ticket seller and max price ticket it can sell. Next, we have an integer k which represent total no of tickets to sell. Our goal is to ...
-3
votes
7answers
107 views

How to decide if I should use global variables or should I use the heap?

I have a question about memory management and global variables versus heap and how to decide whether to use a variable whose space is allocated from the heap instead of global variable. I understand ...
0
votes
1answer
88 views

Did I correctly perform extract max operation on this max-heap?

I am trying to understand how heaps work. I have the following heap: Now I want to extract the max value. The first thing I do is delete the root 42, then put the last element in the heap (6) at ...
1
vote
1answer
39 views

When are shared library functions loaded into the heap?

(This question concerns only the logical addresses) I was experimenting with some code where I print out the addresses of different types/scopes of variables to better visualize the process image. ...
1
vote
2answers
69 views

How can a C++ application use more Heap than RSS Memory?

I have a C++ executable for a multithreads application which involves the opening of UDP ports. I'm measuring the memory usage of this application using different tools. From my understanding of ...
0
votes
0answers
24 views

how to store and read large java objects to hardrive instead of heap memory in java

we have a requirement where we have to load a large volume of data which may require 150+ GB heap memory, we can't afford that much memory, tried ehcahe working fine with fast accessing but consuming ...
-1
votes
1answer
37 views

Why is _siftup and _siftdown just the opposite in Python?

From the definition of binary heap in Wikipedia, sift-up is also called up-heap operation, and sift-down is called down-heap. So in heap (complete binary tree), up means from leaf to root, and down ...
0
votes
1answer
135 views

how to avoid using _siftup or _siftdown in heapq

I have no idea how to solve following problem efficiently without using _siftup or _siftdown: How to restore the heap invariant, when one element is out-of-order? In other words, update old_value ...
1
vote
0answers
19 views

How can I print all rows using python's guppy

I am using python's guppy in order to see heap usage in a python program. I do: h = hpy hp = h.heap() print hp and this is the produced output: Partition of a set of 339777 objects. Total size = ...
0
votes
2answers
61 views

A way to recover memory leak from dynamic allocation in C++?

If I write: b = new int; b = new int; delete b; I know that only the second b gets deleted from memory. Since there is nothing pointing to the first b (due to the deletion of 2nd b), I have a ...
-2
votes
1answer
46 views

Should I delete a used pointer which i created in a function?

Yo,I was messing around with singly Linked LIsts in C++ and I came across this confusion.I created a pointer in an insert function and I wasn't sure if it was going to be deleted afterall. I thought ...
1
vote
1answer
183 views

How to create an auxiliary data structure to keep track of heap indices in a minheap for the decrease_key operation in c++

I think this is probably a trivial problem to solve but I have been struggling with this for past few days. I have the following vector: v = [7,3,16,4,2,1]. I was able to implement with some help ...
-1
votes
0answers
36 views

Heap Block Overflow, what is it and how do i find it?

Im writing a program to Practice AVL trees and Valgrind has determined that I have a memory error. After some googling of the error it seems to be a heap block overflow. I don't know what that is nor ...
0
votes
1answer
35 views

Finding winner and second winner

I was going through this post about the complexity of finding winner and second winner in least comparisons. The post says that it will take n + log(n) - 2 comparisons to do so. I understand that it ...
0
votes
1answer
51 views

Where is an array stored in memory in Javascript? [closed]

We know objects are stored in the heap area. Suppose we are inside a function block where we declare: var a=[1,2] And var b=new Array(1,2) Will both the array objects be stored on the heap or ...
0
votes
1answer
31 views

strange heap out of memory nodejs

My node server is getting heap out of memory now n then. I tried so hard to debug but problem is still same. I am getting this error FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript ...
0
votes
0answers
43 views

Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

I am getting ineffective mark-compacts near heap limit allocation error while running my angular application. I have tried reinstalling nodejs and npm. I tried increase size by using command node --...
1
vote
0answers
21 views

Why use heap over red-black tree?

The clear difference is that a red-black tree can support O(logn) removal, compared to heap's O(n) removal. However, it looks like all operations for a red-black tree are faster/equal tothose of a ...
0
votes
1answer
53 views

Homework C programming stack and heap with string

This is a homework assignment that I could use some help with. I seem to have everything working, but I am having issues with the the name of the games. As you can see my names are not showing up ...
0
votes
3answers
65 views

java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread “main”’ for a file of more than 4GB

Using this tool, https://github.com/citygml4j/citygml-tools, which is called to-cityjson. I want to convert a cityGML file to a cityJSON file. The file is 4.36 GB, but i get the following error: ...
0
votes
1answer
65 views

Why the memory allocation failed when passing the pointer as argument

I just tried two piece of code to allocate contiguous memory for a 2D array and use g++ to compile the code. The second piece of code works well but the fisrt one will lead to Segmentation fault (core ...
-2
votes
3answers
64 views

Priority stack in C++

C++ standard library provides a priority queue with priority_queue. But does it also provide a priority stack ? I looked for priority_stack but did not find anything.
0
votes
0answers
47 views

Minimum heap and heap sorting Algorithm in c

Hello I got stuck in coding arithmetic operation. Please help me to find the right numbers.. I used the number: 22,17,49,55,18,69,24,30,20,21. For the minimizing heap I've got: 17,18,24,20,21,69,49,...
3
votes
3answers
40 views

Dynamic allocation store data in random location in the heap?

I know that local variables will be stored on the stack orderly. but, when i dynamically allocate variable in the heap memory in c++ like this. int * a = new int{1}; int * a2 = new int{2}; int * a3 =...
2
votes
1answer
42 views

Is heap (heapq) in python stable?

if heaptify this [(10,'Mike'),(20,'Jack'),(10,'Bob')] And return the min of the heap, will it guaranteed to return (10,'Mike') and not (10,'Bob') ?
8
votes
2answers
296 views

Is there a particular reason that stacks and heaps aren't mentioned more often in C++ resources?

In books such as "C# in a Nutshell", what is allocated on the stack and heap is introduced quite quickly. However, C++ sources such as "Programming Principles and Practice Using C++", the standard, ...
0
votes
0answers
44 views

Minheapify method

Problem desc: i seem to have a problem with my MIN-heap structure. I get the nullpointer in the min-heapify method in the first if-statement. The test class doesnt matter in this case Can anyone spot ...
2
votes
1answer
27 views

ptmalloc_lock_all weird for loop

I'm trying to understand some of the code in glibc. Why go for this strange for loop? I'm guessing compiler optimization for some reason? 237 for (ar_ptr = &main_arena;; ) 238 { 239 ...

http://mssss.yulina-kosm.ru