Questions tagged [max-heap]
148 questions
0
votes
2 answers
Need Help Counting number of swaps in a MaxHeap
I'm currently working on a project where I have to create a max heap. I'm currently using my textbooks version of the heap which somewhat looks like:
public MaxHeap(int initialCapacity) {
if (initialCapacity < DEFAULT_CAPACITY)
…

Paul Anthony Morillo
- 133
- 9
0
votes
1 answer
How can I fix my remove(Comparable e) method on a Max Heap?
I'm trying to remove(Comparable e) object say remove(2), but when I try to remove it removes the incorrect node in the heap and not the one that I want it to be removed.
This is what the output looks like.
The heap before removing Redwoods NP:
Bryce…

Henry
- 13
- 5
0
votes
1 answer
java: cannot infer type arguments for MaxHeap<>
just running into some issues by making a heap. I have restricted bounds based on the interface I'm working with and i'm trying to access a constructor that efficiently adds a heap to demonstrate that the time complexity is reduced as opposed to…
0
votes
0 answers
Max Heap MaxHeapify Java Not finishing
Having trouble with the constructor for MaxHeapify when there are more than 2 numbers that need to be ordered. stepping thru the code, it works for the first few and then continues without properly ordering the numbers.
i am not sure why this isn't…

Andrew
- 1
- 1
0
votes
1 answer
Determine whether a binary tree is max heap
I am writing a function to determine whether a given binary tree is a max heap. If the binary tree had only one node (the root), would it be considered a valid max heap?

ceno980
- 2,003
- 1
- 19
- 37
0
votes
1 answer
using comparable in java for Bubble up in MaxHeap
I am trying to insert in a maxHeap in java and then bubble up the object. This is what I have done, I am not sure how I should approach the bubble up method.
I do understand the algorithm behind bubble up, which is as follows:
get parent node
see…

Rissalat Ahmed
- 11
- 1
- 5
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
1 answer
In Max-Heapify algorithm, what's the purpose of verifying that left and right elements are smaller than the heap-size?
Here is the psuedocode of the Max-Heapify algorithm :
MAX-HEAPIFY(A, i)
1. l <- Left(i)
2. r <- Right(i)
3. if l <= heap-size[A] and A[l] > A[i]
4. largest <- l
5. else largest <- i
[...]
What's the purpose to verify that the index of the left…

Alexia
- 1
0
votes
1 answer
Is the median of a binary max-heap always a leaf node?
If I have a binary max-heap (a nearly complete binary tree with the max-heap property), then will the median always be a leaf node? I've found some examples where this is the case, but haven't found a counter example -- though this isn't enough for…

Paradox
- 4,602
- 12
- 44
- 88
0
votes
2 answers
HeapSort - Sorted before swapping
I was working with algorithms and specifically heapsort. From my understanding the heapsort algorithm involves preparing the list by first turning it into a max heap.
Turning my
[2, 8, 5, 3, 9, 1]
Into
[9, 8, 5, 3, 2, 1]
With heapsort I am supposed…

Rainoa
- 491
- 1
- 4
- 14
0
votes
1 answer
Find the 10-th largest elements of a Max-Heap in O(1) time
I'm trying to implement an algorithm to find the 10-th largest elements of a Max-Heap with n distinct elements in O(1) time.
I tried to draw it and using the heap property but it gets more and more complicated as I go deeper in the heap. This is a…

user21312
- 143
- 8
0
votes
1 answer
How can I change this code from min heap to max heap
I have the implementation for Dijkstra with min heap, and I tried to change min heap to max heap to find the maximum path, but I could not, the output was wrong
so, please could you help me to change this implementation to max heap?
many…

Salwa
- 9
- 1
0
votes
1 answer
Most Efficient Way to find the logn th Maximum in a Max Heap
The title says it all; What is the most efficient way to find the log nth maximum number in a max heap with n elements?
ps: The text book I'm reading vaguely explained a solution with time complexity of O(lognloglogn) by using another heap that I…

Amen
- 1,524
- 5
- 22
- 41
0
votes
1 answer
Max Heap segmentation fault
Hello dear computer lover. I have once again a problem.
I am supposed to program a Max-Heap. The heap.h and main.c are pre-set and should be correct.
I will now implement 5 functions:
Insert_heap
Heapify
Heap_create
Free_heap
Extract_max_heap
So…

CL89
- 13
- 3
0
votes
2 answers
How to properly assign huge heap space for JVM
Im trying to work around an issue which has been bugging me for a while. In a nutshell: on which basis should one assign a max heap space for resource-hogging application and is there a downside for tit being too large?
I have an application used to…

pnkkr
- 337
- 3
- 15