heap Questions
3
I've been trying to use the Heap package in Go and I am not sure on how to initialize it.
package main
import "container/heap"
type PriorityMessage struct {
Priority int
Message string
}
func...
Koontz asked 27/11, 2019 at 21:51
3
Solved
What is the official way of peeking in a python heap as created by the heapq libs? Right now I have
def heappeak(heap):
smallest = heappop(heap)
heappush(heap, smallest)
return smallest
which...
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
5
Solved
I couldn't figure out the difference (other than ordinality of push/pop actions) between functions heapq.heappushpop() and heapq.heapreplace() when i tested out the following code.
>>> fr...
2
Solved
def heapify(A):
for root in xrange(len(A)//2-1, -1, -1):
rootVal = A[root]
child = 2*root+1
while child < len(A):
if child+1 < len(A) and A[child] > A[child+1]:
child += 1
if rootVa...
Encratia asked 7/8, 2018 at 21:29
5
Interview Question:
Edited Below
You are given an array. You make 2 heaps out of it, one minheap and the other max heap. Now find the median of the array using these 2 provided heaps in O(nlog n) ...
Kara asked 2/2, 2011 at 17:20
20
Python includes the heapq module for min-heaps, but I need a max-heap. What should I use for a max-heap implementation in Python?
Supereminent asked 23/3, 2010 at 15:58
3
I'm very new to C++, and I was wondering if there was a way to make a min heap in C++ from the standard library.
Plutocrat asked 7/5, 2010 at 5:29
3
Solved
Python has heapq module which implements heap data structure and it supports some basic operations (push, pop).
How to remove i-th element from the heap in O(log n)? Is it even possible with heapq...
6
Solved
I understand how to delete the root node from a max heap but is the procedure for deleting a node from the middle to remove and replace the root repeatedly until the desired node is deleted?
Is O...
Urus asked 2/1, 2012 at 20:38
4
I'm trying to implement an algorithm to solve the skyline problem that involves removing specific elements from the middle of a max heap. The way I currently do it is maxheap.remove(index) but I ha...
Psychometry asked 31/10, 2017 at 17:26
8
Solved
I am writing code of dijkstra algorithm, for the part where we are supposed to find the node with minimum distance from the currently being used node, I am using a array over there and traversing i...
5
How to use queue.PriorityQueue as maxheap?
The default implementation of queue.PriorityQueue is minheap, in the documentation also there is no mention whether this can be used or not for maxheap.
Passmore asked 19/12, 2016 at 8:54
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
19
Solved
Can someone help explain how can building a heap be O(n) complexity?
Inserting an item into a heap is O(log n), and the insert is repeated n/2 times (the remainder are leaves, and can't violate the...
Etty asked 18/3, 2012 at 3:15
3
When making a binary max heap, why is it better to implement it as a array based, and not a tree based (tree based as in, each node also having a pointer to it's parent)?
In terms of run time analy...
Scarper asked 5/2, 2013 at 23:37
9
Solved
A heap is a tree data structure where higher levels of the tree always contain greater (or lesser, if it's set up that way) values than lower levels. "The" heap is a bunch of free RAM that a progra...
Egerton asked 16/4, 2009 at 16:9
8
The heap property says:
If A is a parent node of B then the key of node A is ordered with
respect to the key of node B with the same ordering applying across
the heap. Either the keys of pare...
Rikkiriksdag asked 14/8, 2014 at 23:47
8
Solved
I can't seem to find a definitive answer for this, I'm trying to do some elementary proofs on heaps but here's what's throwing me off a little bit:
Is an empty tree valid? If so, what is its heigh...
Viridissa asked 5/2, 2010 at 19:24
3
Solved
In python there's a built-in heapq algorithm that gives you push, pop, nlargest, nsmallest... etc that you can apply to lists. However, there's also the queue.PriorityQueue class that seems to supp...
Gamut asked 2/5, 2016 at 21:6
4
Solved
How is the bottom up approach of heap construction of the order O(n) ? Anany Levitin says in his book that this is more efficient compared to top down approach which is of order O(log n). Why?
Nitrogenous asked 25/3, 2016 at 19:33
10
Solved
Possible Duplicate:
Rolling median algorithm in C
Given that integers are read from a data stream. Find median of elements read so far in efficient way.
Solution I have read: We can us...
4
Solved
What is the complexity of the addAll method of PriorityQueue. Does it add one element at a time resulting in O(n log n) or does it use a build heap process that creates a heap out of unordered elem...
Astroid asked 14/1, 2013 at 1:10
4
Solved
I was looking at this pycon talk, 34:30 and the speaker says that getting the t largest elements of a list of n elements can be done in O(t + n).
How is that possible? My understanding is that crea...
Entourage asked 13/4, 2014 at 3:24
5
Solved
My question is from the solution in leetcode below, I can't understand why it is O(k+(n-k)log(k)).
Supplement: Maybe the complexity isn't that, in fact I don't know the time complexity of heappush...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.