Questions tagged [binary-heap]
225 questions
0
votes
1 answer
Error Adding Multiple Items to a Priority Queue with a Fixed Size Array
before we get started, yes this is homework.
hopefully I can get some clarification here. I am implementing a priority queue with a fixed size array and have all the functions written and everything compiles but I am having a problem with the option…

Blankets_McGee
- 17
- 1
- 1
- 6
0
votes
0 answers
Heap Tree implementation in C
I am practicing data structures in c for an upcoming summer course. I am trying to implement a binary heap tree. And was just wondering if my code is correct or if it could be improved. I have a number of utility functions for making the tree and…

Santi GS
- 87
- 1
- 3
- 9
0
votes
2 answers
Function of key in Binary Heap
I have got this Binary Heap implementation code in my text book using class. But i don't understand the necessity of key in building a heap.
#define MAXREAL 999999.0
class HeapItem
{
public:
int data; //actual data that is stored
…

Leolime
- 197
- 1
- 1
- 11
0
votes
1 answer
Maintaining a Min heap on deletion c++
Test case:
8,7,5,2,3,6,9 (NOT min heap) (this is element A* for buildHeap function)
2,3,5,7,8,6,9 (min heap after calling build heap)
3,5,6,7,8,9 (after calling deleteMin) THIS IS INCORRECT
it should be this 3,7,5,9,8,6
I can't seem to find the…

Marke
- 189
- 4
- 13
0
votes
2 answers
All purpose of binary heap
Definition:
A priority queue is an abstract data type which is like a regular queue or stack data structure, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served…

overexchange
- 15,768
- 30
- 152
- 347
0
votes
1 answer
Formation of Binary Heaps using Arrays Shortcut
If we arrange array in ascending order, then we'll get Binary Heap. Is there any drawback of this advantage. If yes then what will be the reason of that?

Knowledge Reg
- 11
- 1
0
votes
1 answer
Max heap throwing index out of bounds
Below is my max heap implementation. I can really figure out why I am getting the index out of bounds error. I have assigned array to self.heap
class heap:
def __init__(self):
self.heapsize=0
self.heap=[0]
def…

user1006915
- 19
- 1
- 2
0
votes
1 answer
Heap insertion and deletion
Firstly, I have to delete 7 from the heap and after that add 17 and 14.
The problem is I dont know what that heap is. Is it a min heap? or a binomial heap?
Can any of you explain me how to do it (or/and) draft each operation?
Thanks

Nubzor
- 522
- 1
- 5
- 14
0
votes
1 answer
Finding node's postion in array(as binary heap)
Assuming I want to insert a node into a binary heap, how can i find the index of the node in the array that representing the heap after the insertion and the heapifying?
I need to find this algorithm in O(log(log(n)).
Thank you all.

ChikChak
- 936
- 19
- 44
0
votes
2 answers
Max Heap is not working as expected
My Java code for Max Heap is not working as expected. Also it is not returning 90 as max when I remove from heap.
/**
* Created by mona on 5/25/16.
*/
public class Heap {
private int[] heap;
private int size;
private int maxSize;
…

Mona Jalal
- 34,860
- 64
- 239
- 408
0
votes
1 answer
What is the logic behind inserting values into binary heaps (when build one)?
I have a midterm exam next week and am having difficulty drawing out a binary heap. The invariant for a minimum binary heap is: the value of the item stored at a parent node is always less than (greater than) the values of the items stored at its…

thatsnifty
- 191
- 4
- 14
0
votes
1 answer
C: initializing a binary heap
I'm working on a project where I'm implementing a binary heap in C. I'm given Python code for this task, and I essentially need to "translate" the Python to C. I'm having some trouble dealing with translating "self" in Python to the equivalent in…

TyCharm
- 325
- 1
- 2
- 16
0
votes
2 answers
Heap implementation of priority queue?
I'm trying to implement a queue of patients using a heap (with root smaller than children) but when I print the queue, the queue of patients doesn't look prioritized.
Insertion method works fine but it's the enqueue that doesn't prioritize…

Square-root
- 853
- 1
- 12
- 25
0
votes
1 answer
Heaps and Binary Search Trees
What is the run-time associated with (Max-heapify) that is implemented using k-ary heap.
Is a k-ary heap more efficient than a binary heap asymptotically speaking?
Is a k-ary heap more efficient than a binary heap in practice?
can a search tree be…

Omar Kayali
- 113
- 1
- 2
- 7
0
votes
0 answers
heapify function recursing endlessly
The following is a recursive heapify function for an array based priority queue/binary heap.
Can anybody tell me why I'm going into an infinite recursion?
private static void heapify(int i){
if(i < b_heap.size()/2){
int left = i * 2;
…

jokeSlayer94
- 143
- 1
- 9