Questions tagged [min-heap]

181 questions
1
vote
2 answers

Is minimum heap sorted by "default"

I just picked up "Introduction to algorithms", and I started implementing heaps and heapsort algorithm in c#. Implementing a function that constructs a min/max heap from an array of doubles, i noticed that the constructed heap has some interesting…
1
vote
3 answers

Is binary tree that is just None can be considered a min-heap tree?

I need to write a recursion for a min-heap binary tree to check if this tree is min-heap. One of the test cases is just NONE. Is None considered a min-heap tree and returns True, or None is False? The reason I am asking is that I will reach leaves…
1
vote
2 answers

Various issues with binary tree minheap implementation in C

I'm trying to implement a binary search tree in C by using minheap. I've got the basic code down but I cannot get it to work properly. My main problem, according to the build messages, seem to be that I compare pointers and integers. As this code is…
enenra
  • 111
  • 1
  • 11
1
vote
1 answer

How to access objects in a min-heap directly, java

public class Link { public int weight; public int loc; public Link next; public boolean visited; public Link parent; public Link(int d, int loc){ this.weight = d; this.loc = loc; this.visited = false; } public Link(Link p, int d, int…
Graham03
  • 31
  • 4
1
vote
2 answers

BubbleDown operation on binary min-heap does not work

I'm trying to extract the minimum from a binary heap but it's not working. Here's my BubbleDown code: void heapBubbleDown(Heap * const heap, int idx) { int min; while(RIGHT(idx) < heap->count) { min = LEFT(idx); …
rfgamaral
  • 16,546
  • 57
  • 163
  • 275
1
vote
1 answer

Implementing a priority queue with a min heap

I am attempting to implement a priority queue using a minheap, but my objects are coming out of the queue in the wrong order. My intuition tells me the issue is with my methods for sifting up or down in the queue, but I can't see where the issue is.…
aerophage
  • 53
  • 5
1
vote
1 answer

How to "heapify" array based min heap after remove min?

How would I "heapify" an array based minimum heap in java once the remove min function has been called (this simply takes the element at index 1 and removes it, and then replaces it with the last item in the array). I'm confused as to how I would go…
Vimzy
  • 1,871
  • 8
  • 30
  • 56
1
vote
1 answer

Need assistance with the result of a simple Leftist Heap Insert

I have a (min) Leftist Heap as show below: 1 / \ 8 6 / \ / \ 10 12 14 16 /\ / 18 20 22 And I am asked to show the result of inserting 21.…
Rekson
  • 1,293
  • 3
  • 12
  • 13
1
vote
2 answers

Proving that maximum item in a min-heap must be at one of the leaves

How can I go about proving that maximum item in a min-heap must be at one of the leaves, in a tree with N items? I understand the overall design of a min-heap, and I can show/diagram that the maximum item is at one of the leaves (node at depth N +…
1
vote
1 answer

Implementing Min Heap in C - using array?

I am trying to learn and implement a min-heap to solve a problem: Loop that creates doubles and insert them into sorted array, in C Basically, I start with a set of doubles, sorted from smallest to largest. Then, I generate doubles (possibly at…
Legendre
  • 3,108
  • 7
  • 31
  • 46
0
votes
1 answer

Unexpected behaviour of self implemented priority queue using min heap

I implemented a priority queue using a min heap in c++; here I use zero based indexing in the vector used; so for example the left and right nodes of index 5 would be (2 * 5 + 1) and (2 * 5 + 2); I use recursive functions like swim and sink…
Xowaga
  • 11
  • 2
0
votes
1 answer

Finding the maximum and minimum value inside a "max-min" heap in constant time

So, I was given an "opposite structure" to a "min-max" heap, that is called a "max-min" heap. For every node in even depth, the value of the node is greater or equal to the value of its children. For every node in odd depth, the value of the node…
0
votes
0 answers

Want to understand why PriorityQueue.addAll method is not considering comparator

I have the below code written to add a collection of Integers to the Priority Queue. I am getting confused on the out put public static void main(String[] args) { int[] pipes = {4, 3, 2, 6 }; PriorityQueue minHeap = new…
0
votes
0 answers

Issues with insertion function for binary min-heap priority queue

I'm currently struggling with an assignment involving the implementation of a priority queue using a binary min-heap. The user inserts values upon startup, and then has the options to insert more values, delete the minimum value, or print the…
hadcol
  • 1
  • 1
0
votes
1 answer

How to preorder traverse a min heap using array indexing

I created a standard min heap class. I am trying to figure out a way to index the values in the min heap in preorder traversal format. The only way I have seen it done is using left and right pointers. But the "nodes" in my array are not nodes just…