Questions tagged [max-heap]
148 questions
1
vote
1 answer
What are the possible keys for last insert operation? Max Heap
20
/ \
18 19
/ \ / \
10 13 15 1
/\ /\
…

Sharon Denys
- 11
- 1
1
vote
2 answers
What happens if we iterates build-max- heap in Top Down Manner
what are the disadvantages if we construct build heap in top down manner with brief time complexity calculation.in brief using first buid-max-heap heap algorithm than commonly used second algorithm
Build-max-heap(A)
{
A.heap-size=A.length
…

vernol
- 15
- 8
1
vote
1 answer
algorithm that checks if an array of generic type is a MaxHeap
This is my code. I'm quite new to c and pointers so probably the mistake its on pointers.
#include
#include
typedef int (*comparatorPtr)(void*, void*);
bool isMaxHeap(void **heap, int index, int length, comparatorPtr…

DaveJ
- 13
- 2
1
vote
2 answers
Sorting an array with heap sort
I was working my Algorithm's midterm review and I tried to implement all the pseudo codes by Java in order to have a better understanding of algorithm. But on the heap sort part, there was something wrong with my code. My input array is…

K.Wang
- 29
- 1
- 4
1
vote
1 answer
Max-heap representation of an array
As a homework problem, I have to draw out the max heap from an array. The question reads:
Please draw out the max-heap stored in the following array (heapsize is 6)
A[] = {15,10,8,5,2,7,20,30}
So, when I attempted this question, I just did it the…

killerhunterman
- 11
- 3
1
vote
1 answer
Max Heap Implementation
What corrections should I make to the following MaxHeap Implementation in Java?The Insert function keeps running when called. What is the error in the Insert and the BuildHeap functions?I have edited the PercolateDown function. I think it should be…

codeislife
- 319
- 2
- 8
1
vote
2 answers
BUILD-MAX-HEAP running time for array sorted in decreasing order
I know that the running time for BUILD-MAX-HEAP in heap sort is O(n). But, if we have an array that already sorted in a decreasing order, why do we still have O(n) for the running time of BUILD-MAX-HEAP?
Isn't it supposed to be something like O(1)?…

mskeira
- 25
- 1
- 5
1
vote
4 answers
Deleting a node A[i] from a Max-Heap
CLRS Exercise: 6.5-8
The operation HEAP-DELETE(A,i) deletes the item in node i from heap A. Give an implementation of HEAP-DELETE that runs in O(lg n) time for an n-element max-heap.
I wonder if the algorithm is wrong for the input…

sagar_jeevan
- 761
- 5
- 16
- 34
1
vote
0 answers
JVM keeps calling garbage collector for no apparent reason
While testing MaxFreeHeapRatio and MinFreeHeapRatio I found the following situation:
Application heap profiling
Garbage collector activity profiling
So, the JVM keep executing the garbage collector even though there is lots of free memory…

Fábio Mestre
- 21
- 3
1
vote
2 answers
GoLang Heap and Heapsort
So I'm trying to implement a max heap for practice so I can get familiar with Go.
type MaxHeap struct {
slice []int
heapSize int
}
func BuildMaxHeap(slice []int) MaxHeap{
h := MaxHeap{slice: slice, heapSize: len(slice)}
for i :=…

praks5432
- 7,246
- 32
- 91
- 156
1
vote
0 answers
my heapsort is not working. I couldn't find the bug
I'm trying to learn heapsort. I follow the pseudocode instruction, however, my program doesn't work properly. I have already debugging for an hour now and couldn't find the bug. There are a couple of bug: first, the arraylist doesn't sort properly;…

Joe Jame
- 11
- 1
1
vote
2 answers
maxheap method of heapSort with index 0 and not index 1
I have this code for heapSort which works fine. I also understand how the algorithm works when the start index is 1 and not 0. My question is that the maxheap method by itself below works for all indices greater than zero, but not at index 0.…

eagertoLearn
- 9,772
- 23
- 80
- 122
1
vote
1 answer
How is the time complexity of creating a max heap O(n)
How is the time complexity of creating a max heap O(n). Is it that the child node will compare with its parent in only O(i) or is it O(log n).

user2853207
- 21
- 2
1
vote
1 answer
Implementing MaxHeap with Key,Value Pair
I'm implementing a MaxHeap in Java that is sorted on the basis of its key. Each key is also associated with a value. When I try to run my program I get an Exception : Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object;…

Nick Chris
- 281
- 2
- 7
- 17
0
votes
1 answer
What is the value of i if nums size is not equal to capacity?
I am studying max heap and in it there is a createheap function. In it , there is a for loop like this
for (i = 0; i < capacity; i++) {
h->arr[i] = nums[i];
}
if size of nums is not equal to capacity then does the variable i gives…

Uday_singulariy
- 11
- 2