Questions tagged [max-heap]

148 questions
-1
votes
1 answer

STL Priority queue with custom comparator not working as expected

I'm trying to implement Priority queue with custom operator. The algorithm tries to find the minimum increments to be done so that no two adjacent elements in array have absolute difference > 1. For this, I get the maximum element "x" in the array…
Manav Chhibber
  • 678
  • 3
  • 16
-1
votes
1 answer

Extract the root from a max heap

I am struggling to write a recursive algorithm to extract the max(root) from a max heap. The heap is constructed as a tree. I know that I should swap the last node with the root and push it down recursively. But there is no pseudocode on the…
TuMama
  • 307
  • 1
  • 2
  • 8
-1
votes
1 answer

What operations would you use for implementing a priority queue PQ with enqueue and dequeue?

Assume that you are implementing a priority queue PQ that returns the max element on dequeue operation. If we use a max heap to implement the PQ, enqueue is O(______) operation, and dequeue is O(_____) operation Could someone please answer/explain…
-1
votes
1 answer

What is the best algorithm to find the minimum element in max heap?

What is the best algorithm(in terms of time complexity) to find the minimum element in max heap?
-1
votes
1 answer

is it a Heap Max?

For a project, am i working with heaps. In this project i have to "investigate" whether an array is a max heap. These 2 rules apply for a max heap: The parent shall be bigger or equal to its child / children Each node, in a heap, shall contain an…
Buster3650
  • 470
  • 2
  • 8
  • 19
-1
votes
1 answer

Max heap of nodes java

I currently need to implement a max heap of nodes where my node class keeps track of the data, the parent and then the left and right child. My insert method for max heap is taking forever to fill with an array of 100 strings. Here is my code: ` …
James
  • 3
  • 4
-1
votes
1 answer

top-k largest element from the max heap

I am a mechanical student and I have changed my field to Computers. Need to get through the algorithms class. This question is one of the exercise questions If the max heap algorithm's running time is O(klogn) then is there any algorithm which has…
-2
votes
1 answer

List all the keys that could have been the last key inserted in a Max heap

30 / \ 25 20 / \ / \ 22 18 17 16 / \ / \ /\ 21 13 15 5 2 1 Above is a Max-heap created following a sequence of inserting and removing operations. If we assume that the last operation was an…
zin203
  • 11
  • 3
-2
votes
1 answer

Can anyone tell me why this is throwing TLE

Why is the code, below, throwing a TLE? Even the time complexity is O(n) it is throwing TLE QUESTION:https://leetcode.com/problems/sliding-window-maximum/ You can take this website as your…
-2
votes
1 answer

I have written a max_heapify code but it is not providing the required result

I took heap size as 14 as it is the initial size of the array, I was doing question 6.2-1 from introduction to algorithms clrs. I did not some other helper function like swap or 'to print array' I am not very clear on heap size void max_heapify(int…
-2
votes
1 answer

HeapSort returns wrong array (Java)

My HeapSort returns an array that is not in the correct order. My original array is {15, 9, 11, 5, 6, 7}, and when run the heapSort method, I am getting this array: {15, 11, 9, 6, 7, 5}. I printed the method to see what maxHeap did and got: {15, 9,…
Jamie L.
  • 49
  • 2
  • 7
-3
votes
1 answer

How to generate all possible max-heaps from a list of numbers?

The max-heaps can have arbitrary branching factors within the same tree itself. For instance given [8,5,3,1] some of the heaps generated could be 8 or 8 or 8 /|\ | | 5 1 3 5 …
Haskar P
  • 420
  • 4
  • 9
-5
votes
1 answer

insert > priority_queue

priority_queue,int> maxh; error:no default constructor exists for class "std::priority_queue, int, >" If i try this method priority_queue,vector>,int> maxh; for (int…
1 2 3
9
10