Questions tagged [min-heap]

181 questions
0
votes
0 answers

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 the error? Here is the code for the minHeap (Line…
0
votes
0 answers

What will be a complexity of min heap?

What will be a complexity of min heap in my case? I need to figure out 5 smallest numbers in a list. What I do is public List mins(final List list) { final PriorityQueue mins = new PriorityQueue<>(5,…
Pasha
  • 1,768
  • 6
  • 22
  • 43
0
votes
1 answer

How to remove first element from min heap in C?

I can't quite figure out why my removeEntry function doesn't work. I'm trying to implement a min heap for a priority queue ADT. It uses an array of void *'s. I've verified that adding elements to the queue works. For some reason it won't heapify…
0
votes
0 answers

HeapSort implementation has NullPointerException

I have some problems with my HeapSort implementation. For imstance, I don't know how to fix my IndexOutOfBoundsExcpetion. I have not only the HeapSort class in the file, but also the MinHeap class. Tell me if I should add the part of the other file,…
Jo An
  • 5
  • 3
0
votes
1 answer

kth smallest element using min-heap

I was solving a problem of kth smallest element using min-heap but got stuck as it's always giving me the first smallest element, so I guess my extractmin function is not working correctly.My approach was to make array into a min heap data structure…
Hanoi
  • 3
  • 4
0
votes
0 answers

Finding second and third smallest values in a Min-Heap

Is this logic correct? In an efficient minimum heap implemented with an array, it is O(1) to find the smallest value, because it is just the top-most element (the first element of the array. It is also O(1) to get the second smallest value, because…
Austin Cory Bart
  • 2,159
  • 2
  • 19
  • 32
0
votes
1 answer

Dijksta's algorithm - Adjacency List and Min Heap - java

I have used this code to implement the undirected graph and finding the shortest path from node 0 to 5. The code is printing the total distance as the following: Source Vertex: 0 to vertex 5 distance: 10 However, I am looking to print the shortest…
Maya
  • 27
  • 6
0
votes
0 answers

output formatting, using a for loop or while loop to incrementally print nodes in a heap

I have a nearly fully functional program but I am not able to format the output correctly. I am in desperate need of help as my project is past due already. I am a student working on a program that reads in a simple text file and creates a graph…
Trixie the Cat
  • 317
  • 3
  • 18
0
votes
1 answer

Array based MinHeap

I am trying to implement a function that turns a list into a MinHeap. I cannot see where I am going wrong. def min_heapify(nums): n = len(nums) - 1 i = n // 2 # last parent while i >= 1: k = i v = nums[k] …
Wizard
  • 1,533
  • 4
  • 19
  • 32
0
votes
1 answer

What's the diffrence between max-heapify and min-heapify?

Actually I've also heard of the two terms which are- reheapification upward and reheapification downward. But what is the meaning of max-heapify and min-heapify? Are these two terms(max-heapify and min-heapify) somehow related to reheapification…
guptasaanika
  • 137
  • 1
  • 3
  • 9
0
votes
2 answers

how to use pointers to array for Min Heapsort in C?

I was trying to make heapsort using min heap, that too with a Structure that points to a array pointer. Now there is some logical error either in createHeap function or in heapify function. Note:Rest of the program need not to be check or edit,…
0xC0d3
  • 77
  • 1
  • 10
0
votes
1 answer

What are the cases where tournament tree ( Winner Tree) can be helpful?

In the implementation of tournament tree, extra space is used as data to be compared is set at leaves of the tree and then compared.I read that it is helpful when we have to merge k sorted arrays. Now, let's assume we want to merge k sorted arrays.…
shiwang
  • 150
  • 1
  • 13
0
votes
1 answer

Convert heap implemented in array to tree

I have this homework where I have to convert a min-heap represented in array: DEFINE #SIZE typedef int Heap[SIZE] and implement it in a tree like so: typedef struct node{ int val; struct no *left, *right; } Node, *Tree; and as a reminder…
Richard
  • 481
  • 1
  • 3
  • 11
0
votes
0 answers

MinHeap: which approach is best when adding nodes to an array?

I'm working on building a minheap in Ruby and was wondering what the implications would be of using the push method vs an assignment operator. (This is just a theoretical question to understand Ruby better!) @items = Array.new() def insert(node) …
0
votes
0 answers

Sorting edges to find source node for Prim's algorithm

I am trying to implement Prim's algorithm using min-heap. I do not want to randomly choose the source/starting node, but want to sort the edges in non-decreasing order of weight to find the root node. I would like to have guidance as to how to go…