15
votes
Accepted
Priority Queues - Array based implementation
This code looks a lot like C with classes, rather than modern C++. You make no use of the standard library except for std::cout. You ...
12
votes
Priority Queues - Array based implementation
General design
Encapsulation
Some of the member functions provided by PQueue<T> are helper functions which should not be publicly available (e.g. why should ...
11
votes
C++ Thread safe priority queue implementation
Design
Starvation. std::mutex does not guarantee starvation freedom. If there are too many producers and much fewer consumers, on systems with mutexes that don't ...
10
votes
Accepted
C# binary heap priority queue
I opted to make a constructor that allows the option of min or max
order, since it runs on the pathfinder the performance of this is
quite crucial as well. So hopefully some one has some ...
10
votes
Accepted
Planned Economy Bakery - Trying to scale a nested loop with a heap
I think I understood your problem.
Problem description
Given:
num_items - the number of available items
targets - a list of ...
10
votes
Accepted
C++ Thread safe priority queue implementation
Haven't used locks too often, but a few things I noticed in general:
Your code is incomplete and lacks headers, even though it seems to be meant as a complete example (e.g. including ...
8
votes
A stable priority queue in C++
new and delete...
Manual use of new and delete very often leads to leaks. In this case you have a destructor but not any other ...
7
votes
Priority Queues - Array based implementation
const int maxsize = 5;
A couple of things here. First you should prefer constexpr. But furthermore I am curious why you have a ...
6
votes
Planned Economy Bakery - Trying to scale a nested loop with a heap
@Finomnis offers an excellent theoretical and algorithmic analysis. As is my wont, I'll take a different approach and examine your usage of Python.
...
5
votes
Accepted
Priority queue implementation in C based on heap ordered (resizable) array
"The user of the priority queue is expected to define their data type in the data.h header. This is to make the code flexible and not use void*."
Code limits the types available to pointers ...
5
votes
Priority queue implementation in C based on heap ordered (resizable) array
A definite memory leak:
void priority_queue_free(struct priority_queue_t* pq) {
free(pq);
}
doesn't free(pq->array).
A ...
4
votes
Yet Another MinHeap
This is a very nice and clean implementation and looks like there's not much to complain about but I have a few thoughts.
One thing I'm undecided on is restricting ...
4
votes
Priority queue implementation in C based on heap ordered (resizable) array
The other answers make some good points (especially @vnp who caught the two memory leaks — that's a huge deal!). I'll try not to repeat too much.
...
4
votes
Priority queue implementation on C. (For Huffman Coding)
Avoid double pointers. They are absolutely unwarranted in all the functions (except init, but see below).
Prefer returning a value to a side effect. In the client ...
4
votes
JavaScript Priority Queue implementation using a binary heap
Naming
The name Heap is confusing, since this is a priority queue, not a heap. The heap is merely an internal private implementation detail that should not be ...
4
votes
Accepted
LeetCode: Minimum cost to hire k workers
Please review the code as if this was 45 minute interview.
I don't know what you expect from answerers with this statement.
The evaluation of some code produced within 45 minutes is subjective,
highly ...
4
votes
4
votes
Accepted
Priority Queue (With raise priority operation) using Vector
It's not a drop-in replacement
The reason I have effectively reimplemented std::priority_queue is because the STL implementation does not have a raise_priority ...
3
votes
Accepted
Overriding List subscription to create IndexedHeap for Classical Dijkstra's Algorithm
Firstly, it's always good to see doctests.
I'm not entirely convinced by the name IndexedHeap. The API it exposes has nothing to do with indexes.
...
3
votes
Most frequent word in an array of strings - Java
As you noticed, searching for your entries is adding to your time complexity, because you have to run down your queue. Priority queues are very good at polling the top element, but not optimized for ...
3
votes
Priority queue implementation in C based on heap ordered (resizable) array
Off by one bug
When you resize your array, you need to make the new array size capacity + 1 and not just capacity, because your ...
3
votes
Generic PriorityQueue (Min-Heap) implementation
public int Length { get; private set; }
_elements carries the length already, and duplicate state that you keep in sync ...
2
votes
Generic Min Heap Implementation in Java
Exception handling
Throwing Exception is not recommended because it's too generic.
It doesn't give a clue to the caller as to what went wrong.
It's recommended to ...
2
votes
Priority queue implementation on C. (For Huffman Coding)
in function:
void init_queue(struct priority_queue **pq, size_t capacity)
after the final closing brace '}' there is a semicolon ';'. This results in the ...
2
votes
Accepted
Updateable Priority Queue
Your code looks good, there's not much for me to review, but here are a couple improvements/changes I would make.
Improvements
Docstrings: You should include a ...
2
votes
JavaScript Priority Queue implementation using a binary heap
Formatting
The code formatting is fairly consistent in terms of line terminators, though there are a couple lines missing semi-colons - e.g. in swim() and ...
2
votes
Efficient implementation of priority queue
The advice I think most important:
stick to the Style Guide for Python Code
It helps everyone - including yourself - read your code.
Naming: name things for what they can/will be used for, their ...
2
votes
Accepted
Priority Queue for D* Lite
Unnecessary use of this->
It is almost never necessary to use this-> in C++. I recommend you remove all occurrences of it ...
2
votes
Bidirectional Dijkstra d-ary heap
Overview
It is great that you:
Used strict and warnings
Leveraged other people's code by using the ...
2
votes
Accepted
Binary heap based priority queue implementation in C#
Advice I - where TPriority : notnull
I would add where TPriority : notnull to the class declaraction, since the priority keys ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
priority-queue × 72c++ × 20
algorithm × 20
heap × 17
java × 15
python × 9
c × 9
c# × 8
performance × 6
python-3.x × 6
object-oriented × 6
c++11 × 6
programming-challenge × 5
javascript × 4
beginner × 4
multithreading × 3
graph × 3
pathfinding × 3
linked-list × 2
ecmascript-6 × 2
queue × 2
library × 2
clojure × 2
kotlin × 2
compression × 2