Questions tagged [binary-heap]
225 questions
1
vote
2 answers
Why is this implementation of binary heap slower than that of Python's stdlib?
I have been implementing my own heap module to help me understand the heap data structure. I understand how they work and are managed, but my implementation is significantly slower than the standard python heapq module while preforming a heap sort…

chillNZ
- 99
- 1
- 10
1
vote
0 answers
Which container should I choose to implement a heap?
I am trying to make my own libraries in c++ and want to implement heap data structure.
I have already coded all the algorithms for the insert, delete and find for the heap
What I need is a container to hold the heap.
I know that they are implemented…

Rohith R
- 1,309
- 2
- 17
- 36
1
vote
1 answer
Priority Queue in Java which keeps track of each node's position
so I'm working on a lab for my class. I need to create a Priority Queue in Java using an array list. The kicker is that each node has to have a "handle" which is just an object which contains the index of of the node that it's associated with. I…
user1493803
1
vote
2 answers
Min Binary Heap issue
i need help with this minheap code:
#include < vector>
using namespace std;
class heap {
vector v;
public:
int hSize()
{
return v.size();
}
int rsize()
{
return …

user281073
- 13
- 4
1
vote
3 answers
High performance heap sorting
I have a vector of size more than 5 million, each time I would like to pick up one element with the smallest key from the vector, and do some process on this element. However with the process this particular element, all of the remaining elements in…

C. Wang
- 2,516
- 5
- 29
- 46
1
vote
1 answer
How to use Boost d_ary_heap?
I'm trying to use the Boost d_ary_heap but I cannot figure out how to get the handle for a pushed element. In my case, I will need to update the value in a later iteration, so I need that handle. I was able to do it with the Fibonacci heap but in…

Javi
- 3,440
- 5
- 29
- 43
1
vote
2 answers
D: How to create a new, empty binary heap to store integers?
I'm a bit confused about how to properly use the Binary Heap provided in std.container. More specifically, I wanted to create a maximum heap of integers, so I tried writing
auto maxHeap = BinaryHeap!int();
and got a compiler complaint about int not…

Koz Ross
- 3,040
- 2
- 24
- 44
1
vote
2 answers
implementation of binary heap through array
I wan't to make a binary max heap through a given array. I can implement it in two ways:
1.Make a heap of the whole array and start heapifying through leaf nodes to the top.
2.Insert an element one-by-one into the heap from the array and heapifying…
user2847211
1
vote
1 answer
compares for insert operation a binary heap
When you use a binary heap to implement a priority queue ,it is stated that the insert operation requires at most 1+lg N number of compares.(lg N = log of N,to the base 2).
Consider the below picture ,
Here the tree has a maximum height of 3.Even…

damon
- 8,127
- 17
- 69
- 114
1
vote
2 answers
Batch updating node priorities in a binary heap?
I posted quite confusing question, so I rewrote it from scratch...
This is actually purely theoretical question.
Say, we have binary heap. Let the heap be a MaxHeap, so root node has the biggest value and every node has bigger value than it's…

enrey
- 1,621
- 1
- 15
- 29
1
vote
2 answers
Python: Using heap commands on a list of tuples
I'm trying to understand some of Python's built in heap functionality. It seems to not like things when I pass in a list of tuples (or more likely, I'm not passing the list in correctly). Here is what I have:
myList = ( ('a', 1), ('b', 2)…

AndroidDev
- 20,466
- 42
- 148
- 239
1
vote
3 answers
Priority Queue - Binary Heap
I'm trying to implement a priority queue as an sorted array backed minimum binary heap. I'm trying to get the update_key function to run in logarithmic time, but to do this I have to know the position of the item in the array. Is there anyway to do…

Richard
- 5,840
- 36
- 123
- 208
0
votes
2 answers
How to link Two Multi-Dimensional arrays using pointers?
I need to basically merge a Binary Heap, and Linear Probing Hashtable to make a "compound" data structure, which has the functionality of a heap, with the sorting power of a hashtable.
What I need to do is create 2 2 dimension arrays for each data…
Bill
0
votes
1 answer
How to identify vertices that violates Max Heap property?
I am learning binary heap now and I do not really understand this question about Build Heap that violates the property of Max Heap. Could someone explain the answer below for me please?

vt-0307
- 63
- 1
- 7
0
votes
0 answers
Binary heap output not as expected
I have a homework that the teacher test if it's corrects by checking it's output using this website moodle.caseine.org, so to test my code the program execute these lines and compare the output with the expected one, this is the test :
Tas t = new…

Marwane
- 333
- 3
- 13