Questions tagged [max-heap]

148 questions
2
votes
0 answers

Binary Search Tree and Max Heap at the same time (C++)

[EDITED!!!] Having read about different data structures and created many of them (in C++) I just wondering how could we make a data structure where each node would be a pair of keys (x,y), where x would refer to a value of a Max Heap and y to a key…
2
votes
1 answer

How to modify the priority of a value in a max-heap?

I am writing a max-heap, which can change the priority/value. However, I have problems to understand what is wrong in my code. I have followed this as reference: ref This is my code (I have hide some functions since it not the focus here) static…
Anderson Carniel
  • 1,711
  • 2
  • 16
  • 22
2
votes
1 answer

Merge 2 Max heaps

I need to find the most efficient algorithm to merge 2 max-heaps. Some important facts: The heaps are represented as a binary trees, that means that each node has 3 fields - value (key), pointer to right child, and pointer to left child. My idea: to…
Ran
  • 35
  • 1
  • 7
2
votes
2 answers

Remove an element from any position in a max heap

I have a Point object that just has an x and y, and I have a Heap data structure that looks like so: class MaxHeap{ public Point[] heap; public int size; public int maxsize; public MaxHeap(int maxsize){ this.maxsize = maxsize; this.size =…
Talen Kylon
  • 1,908
  • 7
  • 32
  • 60
2
votes
2 answers

Inserting item into a Max Heap

I am not sure on how to insert an item into my max heap and then trickle up so the max heap property holds. I have thrown an exception if the heapArray is full therefore not being able to insert an item. I am not using JCF classes or the priority…
evilA
  • 23
  • 1
  • 1
  • 4
2
votes
1 answer

How to delete the minimum key in a max heap?

I need to implement a function HEAP-DELETE-MIN(Array) that deletes the lowest integer in a max heap. Im not asking for the function itself, but could someone provide me with some pseudocode to help me get started? It would be a great help. The…
Mike
  • 477
  • 2
  • 7
  • 24
2
votes
0 answers

Algorithm to check if k'th smallest element in max-heap is bigger than given number

Possible Duplicate: How we can find kth largest element from a max-heap in O(k) time? There is a given a max-heap, we want to find an algorithm in o(k) time complexity to check if k'th smallest element is bigger than arbitrary given number.
Pooria Kaviani
  • 748
  • 1
  • 8
  • 17
2
votes
1 answer

Find Element in Max Heap

I have a MaxPQ Heap that uses an array to store the elements. What is an algorithm I could use to find a given element in the heap ? The algorithm I am currently using iterates through the array starting with the index 1 and upto the number of…
Nick Chris
  • 281
  • 2
  • 7
  • 17
1
vote
2 answers

Efficient HEAPIFY method to reduce number of comparisons

Consider a binary max-heap with n elements. It will have a height of O(log n). When new elements are inserted into the heap, they will be propagated in the heap so that max-heap property is satisfied always. The new element will be added as the…
taurus05
  • 2,491
  • 15
  • 28
1
vote
3 answers

Print k largest elements in a max heap sized n, in klog(k) complexity

I tried writing an algorithm that prints the k largest elemtns of a max heap but I cannot do it in the right complexity. This is the Pseudo-code I wrote- Print_k_largest(A[1,…,n],k): If k>Heapsize(A):Error i=1 insert[B,A[i]) print(B[1]) k-=1 While…
DR_2001
  • 29
  • 4
1
vote
1 answer

C++ Max Heap not sorting correctly after remove max

I'm attempting to remove the max by swapping the first and last element of the vector and then using pop_back. When I remove max I output max but the reordering process is not working correctly and I cannot figure out why. I have attempted changing…
Jason JR
  • 13
  • 3
1
vote
1 answer

How to build max heap in O(n) time from a given array in java by using PriorityQueue collection?

I am trying to find Kth largest element in a given array of size n. My idea: Build a maxheap from the given array (which takes O(n) time). And then remove (k-1) elements from the maxheap. finally return the topmost element in the heap. I know I can…
1
vote
1 answer

DRAWING Binomial Heap

Would anyone know how to draw a binomial max heap for values 1-10? I am currently learning about heaps in my Data Structure course, but after watching multiple videos I still can't get it! And I am not sure if I am doing it right. I understand that…
webdesignnoob
  • 381
  • 1
  • 4
  • 13
1
vote
1 answer

Is it possible to construct a binary search tree from a Max-Heap in O(n) steps?

I think it is not possible because if it actually is, people would build max-heap and then use it to construct BST which I think is not the case. Please give an answer with a proof.
1
vote
2 answers

Is there a way to fix my Max heapify within my code

The issue is that I am trying to fix the max heapify, it is not working as the error keeps occurring. I have been following the pseudocode from several books, yet errors are still shown. I am trying to exchange the A[i] to A[largest] by using = to…
ryan boss
  • 31
  • 1
  • 7
1 2
3
9 10