min-heap Questions
5
Solved
I am wondering why for creating a min heap using the priority_queue, the std::greater should be used?
std::priority_queue<T, std::vector<T>, std::greater<T> > min_heap;
To me, ...
Durgy asked 23/9, 2015 at 19:36
4
Solved
I'm wondering if a max or min heap tree is allowed to have duplicate values? I've been unsuccessful in trying to find information regarding this with online resources alone.
Tradescantia asked 21/3, 2014 at 21:47
6
Solved
I want to compare the second element of the following array:
int[][] intervals = new int[][]{new int[]{0, 30},new int[]{5, 10},new int[]{15, 20}};
My priority queue with custom comparator:
Priorit...
Oriole asked 6/7, 2020 at 12:7
3
Solved
When using a min/max-heap algorithm, priorities may change. One way to handle this is to removal and insert the element to update the queue order.
For priority queues implemented using arrays, thi...
Ronaronal asked 29/10, 2017 at 1:31
7
Solved
I have the below struct:
struct node {
float val;
int count;
}
I have several objects of this struct. Now, I want to insert these objects into a priority queue of STL such that the priority queu...
Headstand asked 7/2, 2012 at 14:33
1
Solved
I am having trouble understanding why solutions for finding the kth smallest element uses a Max heap approach. And for the kth largest element a min heap approach. Wouldn't it make more sense to us...
2
Solved
I was trying to implement MST with Priorityqueue with custom comparator, but I am facing problem in building min-heap with it in O(n) time. The problem is only one constructor of Priorityqueue allo...
Desmonddesmoulins asked 2/11, 2017 at 17:29
1
Solved
I'm trying to return the running median for a series of streaming numbers. To do that I use a max-heap (which stores the values on the lower half of the series) and a min-heap (which stores the val...
2
Solved
I'm reading about Dijkstra's algorithm in CLRS, Third Edition (p. 662). Here is a part from the book I don't understand:
If the graph is sufficiently sparse — in particular, E = o(V^2/lg V) — we...
Cellulose asked 31/1, 2017 at 18:59
2
Solved
I want to populate a binary heap with floats--more specifically, I'd like to implement a min-heap.
It seems that floats do not support Ord and thus aren't usable out of the box. My attempts to wra...
2
Solved
val maxHeap = scala.collection.mutable.PriorityQueue[Int] //Gives MaxHeap
What is the most concise and efficient way to use Ordering to turn a PriorityQueue into a minHeap?
Ul asked 25/11, 2014 at 5:43
3
Solved
I am trying to make a min-heap1 of longs in C++ using the STL make_heap, etc., but my comparator doesn't seem to be comparing properly. The following is my current comparator:
struct greater1{
bo...
Publias asked 24/12, 2012 at 4:2
3
Solved
for user defined struct, as I understand, it's easy. Just overload the operator <. However, for int/float etc.., do I really need to overload operator < for int?
Here is what I tried:
#incl...
5
Solved
I had an interview with Facebook and they asked me this question.
Suppose you have an unordered array with N distinct values
$input = [3,6,2,8,9,4,5]
Implement a function that find...
1
Solved
I am trying to build a min heap. I have already done the insert, delete,swap, up-heap, down-heap and it is working correctly.
However, I am trying to write a method for Min-Heapify.
Here is my In...
1
Solved
Possible Duplicate:
What do I use for a max-heap implementation in Python?
I am trying to implement in some way the heapq of python but for a max-heap. A solution is using the (-1) an...
1
Is there any simple explanation of Frederickson's heap selection algorithm to find the k'th ranked element in O(k) time in a min-heap available anywhere online? If not, can anyone explain the gut o...
Baxley asked 18/8, 2012 at 0:51
1
Solved
I'm reading CLRS and had some problem with the exercise 6.5-8.
Give an O(n lg k)-time algorithm to merge k sorted lists into one
sorted list, where n is the total number of elements in all the ...
2
Solved
I am trying to implement a min heap in c++ for a struct type that I created. I created a vector of the type, but it crashed when I used make_heap on it, which is understandable because it doesn't k...
Contagious asked 4/4, 2010 at 9:43
2
Solved
I'd like to store a set of objects in a min heap by defining a custom comparison function. I see there is a heapq module available as part of the python distribution. Is there a way to use a custom...
1
© 2022 - 2024 — McMap. All rights reserved.