Questions tagged [min-heap]
181 questions
0
votes
1 answer
How can i fix my implementation a generic Decrease-Key method in a Min Heap in java?
I want to decrease the value of an element with index i in my Min Heap data structure that i am implementing using an ArrayList (and then move the element in the correct position), here is the implementation of it, i will skip the insert, heapSize,…
0
votes
2 answers
What is the meaning of vector*>?
I was solving a question on merging k sorted linked lists and I came across this vector*>:
Node* mergeKLists(vector*> &listArray);
I want to know if it is a declaration of all the linked lists, if it is how it has been…

cosmoabhi
- 1
- 1
0
votes
0 answers
Why it resulting a "list index out of range error" on this dijkstra algorithm
I tried to implement a dijkstra algorithm on my own graph but it doesn't run instead it says that "list index out of range"
here is the code that i tried
it works on a smaller graph like with 6 nodes but mine has 39 nodes and the maker of this code…

Samuel
- 1
- 1
0
votes
1 answer
priority queue question. priority is undefined in while loop. how to enqueue element to queue?
doing a priority queue as a min-heap in javascript. console keeps returning priority is undefined in the while loop. what is the problem? / how to enqueue element to queue?
//min-heap
class PriorityQueue {
constructor(){
this.values = [];
…

AlmostThere
- 15
- 5
0
votes
2 answers
Heap Dijkstra Implementation is slower than Naive Dijsktra Implementation
I have tried to implement the Naive and Heap Dijkstra as shown below but somehow my naive Dijkstra implementation is surprisingly faster. I debugged my code but couldn't understand where my problem in my implementations are.
Why is my heap-based…

Jonsi Billups
- 133
- 1
- 3
- 15
0
votes
1 answer
javascript min heap implementation for a storing a pair/tuple
I created a class to implement a min heap following a tutorial. It works fine for storing and retrieving integers. I want to store pairs in this class for example:
(5, 1)
(2, 4)
(6, 2)
The removeMin method should give (2, 4) back. Please find the…

Ashy Ashcsi
- 1,529
- 7
- 22
- 54
0
votes
1 answer
Why Dijkstra worst time complexity is worse using priority queue compared without using it?
I know the sequence of step of Dijkstra algorithm is like these:
Initialize arr min_distance, put source as 0, and the others as MAX_VALUE
Pick the min distance that's not in visited set
Put vertex to the visited set
Loop through all edges linked…

ktvktv
- 143
- 1
- 2
- 7
0
votes
1 answer
Inserting a node in a min-heap with a null value at the end
I got a sorted min-heap array: 2,3,4,5,NULL
I'd like to insert the value 1 in it, how would the first step be dealt with?
2 2
/ \ / \
3 4 or this? 3 4
/ \ / / \ …

student
- 177
- 2
- 10
0
votes
2 answers
Why is this minHeap implementation incorrect?
I am using a PriorityQueue to solve the Meeting Rooms II problem from Leetcode. I have developed my own solution that fails on certain test cases, yet from my eyes it is indistinguishable from the provided solution, yet that solution passes all…

calvinhobbes123
- 41
- 3
0
votes
1 answer
Which data structure is more efficient for A*?
In A* search, which data structure would be more efficient ? Min-heap or Binary search tree.
Considering that below operations are to be handled frequently:
(a) extract min
(b) search a node
(c) update the node
(d) insert a node
Note: Search…

aks
- 147
- 1
- 9
0
votes
1 answer
What is wrong with my insert function for min-heaps?
I'm trying to write a minimum heap data structure in C, but I ran into some issues while implementing the insert function.
It looks like this :
void insert(MinHeap* minh , int key)
{
if(minh->itemcount == minh->maxSize)
{
…

blake
- 107
- 1
- 7
0
votes
1 answer
What are the boundaries on increasing keys in minimum heap
I was asked this question on a test and would like to make sure I answered correctly:
You are given a min heap. We want to increase all the nodes on the left most path (so the root, node 2, node 4, node 8......) by a value of c, so that the heap…

Yair
- 99
- 8
0
votes
2 answers
Maximum Number of comparison in a min heap to Determine Maximum number
A min-heap consist of 2047 elements, the maximum number of comparisons required to determine the maximum number of elements is _.
For this i went with approach as this is a min heap and the min element will be there in the root node. So to find the…
0
votes
1 answer
In C++, when adding onto a minHeap, which calls the bubbleUp function, how can I lexicographically compare two things that have the same priority?
In C++, when adding onto a minHeap, which calls the bubbleUp function, how can I lexicographically compare two things that have the same priority?
I want the value that is smaller when compared lexicographically to come first in the heap. What…

coderlegend
- 1
- 1
0
votes
0 answers
Merging two binary min-heaps
I have two binary min-heaps, where each one stores different keys. The trees are also complete binary trees. I want to merge these two into one binary min-heap of size exactly 2n. Preferably in O(long) time and O(1) space.

bennietgek
- 65
- 5