Questions tagged [min-heap]
181 questions
-1
votes
1 answer
How to insert elements from a structure into a min heap priority queue
I am making a file compressor using Huffman Algorithm in C++. I have calculated the character frequency, but now I am having difficulty in pushing it into a min heap priority queue. I want to sort the inserted elements by frequency. Every time I…

Muhammad Taimoor
- 55
- 1
- 8
-1
votes
1 answer
error while trying to create a minHeap from array
I'm trying to get a minHeap from an array, but I can't get it right
The input I've tried is: 4 3 2 1
The output I got is: 2 3 4 1
First I tried with using only an array of int for storing the heap and it worked, then I changed and used an array of…

VondeTaconadis
- 64
- 9
-1
votes
1 answer
Why is this implementation of deleting an element from heap wrong?
Here is my implementation of deleting an element from Min Heap if the position of the element to be deleted is known:
void MinHeap::deleteKey(int i)
{
if(heap_size>0 && i=0)
{
if(heap_size==1)
…

NovicE_Neo
- 1
- 3
-1
votes
1 answer
Time complexity higher than expected for min-heap custom functions
I am trying to implement a custom min-heap in python. I want to store tuples in the heap and order them with respect to the second element in the tuple. Here is my attempt at it:-
class minheap():
def __init__(self):
self.heap = list()
def…

Sharan Kumar
- 139
- 1
- 2
- 13
-1
votes
1 answer
How to make min heap in python to store edges and weight
I have a list of edges l=[(0,1),(0,2),(1,3)] likewise, and I have list of weight of edges l1=[0.23,0.45,0]. Now I wanted to store edges in min heap manner, so that I can get access to minimum weighted edge.
-1
votes
1 answer
Trying to print out the elements in the last level of a min heap
I'm trying to print the last level in a min heap. I thought I had code that works, but one of the test cases fail. In terms of the test cases, I only have access to how the output does not match.
Here is my code:
#include "MinHeap.h"
#include…

HughJass24
- 39
- 1
- 4
-1
votes
1 answer
Problem in implementing build-heap method for min-heap
I am trying to make min-heap algorithm and i am able to get insert,delete,pop ,trickleUp and trickleDown methods to work ,but i am having problems with the constructor which is to make use of build-heap algorithm.
The method is simple as it just…

Meet Yeole
- 71
- 2
- 8
-1
votes
2 answers
Getting garbage values when traversing min-heap
This is my traversal method:
void heapTraversal(){
for(int i = 0; i

Arda İbrahim Gökçe
- 33
- 4
-1
votes
1 answer
min heap not working
I'm creating objects of arc type and insert it into heap which should sort them in ascending order but not working the output should be
(B A 4) (B C 8) (B H 11)
but it giving me this
(B A 4) (B H 11) (B C 8)
this is Arc class
public static class…

striker
- 77
- 8
-1
votes
1 answer
Expected behaviour of a stack implemented using Priority Queue using minHeap
I am new to the concept of heaps and PQs. So I was trying to implement a Stack using PQ using a min heap.
I am trying to implement following methods:
pop
pop
isEmpty
top
size
Below is the code:
import java.util.*;
import java.lang.System;
public…

learntogrow-growtolearn
- 1,190
- 5
- 13
- 37
-2
votes
1 answer
OOP linking classes
I have to implement a data structure for a IT ticket system which is ordered by priority. So i am going to implement a priority queue. I have both a linkedlist class(and a node class for this) and a min-heap class but not sure which i want to use…

RHH
- 27
- 6
-2
votes
1 answer
data structure that consists of min-heap and binary search tree(tricky)
I am having really hard time with this and I don't know how to approach it - would really appreciate your help:
A company tries to build a SP tree data structure so that each intersection contains two keys: a sorting key skey that gives SP the…

BeginningMath
- 127
- 6
-2
votes
1 answer
C++ priority queue "greater" option is not working
What is the problem?
When I use priority queue of STL, I want to use min heap, so I used like below code.
It works on default option but it is not working on "greater option".
It always arranges like above picture. I don't know totally why this…

molamola
- 269
- 4
- 15
-3
votes
1 answer
hostel visit question (priority queue application )
question: Dean of MAIT is going to visit Hostels of MAIT. As you know that he is a very busy person so he decided to visit only the first "K" nearest Hostels. Hostels are situated on a 2D plane. You are given the coordinates of hostels and you have…

Ritik gupta
- 7
- 1
-3
votes
1 answer
Is this right? Minheap
Hello, I am wondering if these x's are in the right position for the min heap? Am I correct?

Tinler
- 165
- 6