Questions tagged [priority-queue]
Priority queues are dynamic sets that always remove highest priority elements first.
72 questions
3
votes
0
answers
71
views
Implementation of Indexed Priority Queue
I'm learning Graph Theory and trying to solve the Dijkstra Problem. One of the best ways to solve the problem is to use Indexed Priority Queue and so, I implemented it. The code is below. Pls review ...
3
votes
1
answer
148
views
C++ implementation of a keyed priority queue / binary heap
I wrote an implementation of a keyed priority queue in C++ and wanted to get some feedback on it.
I tried to model it after the std::unordered_map and ...
5
votes
0
answers
117
views
Dial's heap in Java for integer priority queues
(The entire project is here.)
Intro
I have this priority queue data structure for non-negative integer priority keys. I recall that it is called Dial's heap.
Code
Implementation
...
3
votes
1
answer
179
views
Binary heap based priority queue implementation in C#
I made this Priority Queue implementation for C# since it doesn't support updating priorities in logarithmic time complexity. I did some tests and it seems that it's correct. However, I'm not sure ...
7
votes
2
answers
454
views
Priority Queue (With raise priority operation) using Vector
Here I have implemented a priority queue, with the addition of the raise_priority (also known as reduce key) operation. The reason I have effectively reimplemented std::priority_queue is because the ...
5
votes
1
answer
110
views
Bidirectional Dijkstra d-ary heap
This is my very first data structure written in Perl for a d-ary heap:
...
2
votes
1
answer
125
views
Priority Queue for D* Lite
So, I needed a priority queue for D* lite and I wanted to know whether this is an acceptable implementation or not.
...
6
votes
2
answers
4k
views
C++ Thread safe priority queue implementation
My first attempt at writing a thread safe priority_queue. It is not the most efficient because the locks can be even more fine grained if I add implementation of heap instead of using priority_queue ...
2
votes
0
answers
317
views
Kotlin AsyncPriorityQueue
Unbounded threadsafe suspending priority queue
Items are ordered by an integer priority value passed into the enqueue() method
dequeue() retrieves and removes the head of the queue or suspends until ...
2
votes
1
answer
277
views
Minimum Spanning Tree in Rust
As a project I have worked on implementing and benchmarking two different minimum spanning tree algorithms in rust. My main concern is adhering to good style and not programming any glaring ...
1
vote
1
answer
94
views
Assigning Tasks to Entities (or some other entity) based on Priority
Main Questions:
Is my runtime analysis correct?
Is my approach optimal or close to it?
Is there a better way and/or improvements?
Objective:
Write an algorithm to assign ...
2
votes
1
answer
975
views
Generic PriorityQueue (Min-Heap) implementation
I was trying to implement a generic PriorityQueue in C#. Below is my implementation which works fine as per few test cases.
Operations supported-
Add: Adds an element
Poll: Removes the smallest ...
8
votes
2
answers
589
views
Planned Economy Bakery - Trying to scale a nested loop with a heap
Let's say you are living in a controlled economy where there is a baker in town, and every day he bakes a random number of loaves of bread (sometimes the oven breaks, or he has less ingredients). The ...
2
votes
2
answers
557
views
Priority queue implementation on C. (For Huffman Coding)
I trying to implement Huffman Codes on C. And, since my previous attempt failed, I decided to approach the issue more responsibly. So I'm asking for feedback on my implementation of the priority queue ...
4
votes
2
answers
218
views
JavaScript Priority Queue implementation using a binary heap
I'm currently going over Robert Sedgewick's Algorithms book. For the implementation of A priority queue using a binary heap I implemented the code using ES6. I believe to have more experience with ...
6
votes
1
answer
180
views
Efficient implementation of priority queue
I am trying to solve a maze problem.
The input data is a matrix, where the individual element represents the height of the mountain in that particular area,
I have to start from position (0,0) and go ...
2
votes
1
answer
242
views
Priority queue with Max-Heap
I'm studying with book "Introduction to Algorithms" and implemented PriorityQueue without existed Class.
I made a MaxHeap class with Array and made a PriorityQueue with my Heap class.
Actually code ...
2
votes
1
answer
838
views
A simple priority queue in Java via linked list sorted by priority keys
Now I have this very simple priority queue. add and changePriority both run in \$\mathcal{O}(n)\$ and ...
2
votes
1
answer
424
views
Updateable Priority Queue
I've implemented an updateable priority queue as a part of implementing some single-source-shortest-path algorithms (Dijkstra, BF). I'm relatively new to Python.
...
2
votes
1
answer
275
views
Prioritize objects using PriorityQueue and custom comparator in Java
I have a list of objects and a query. I need to rank the objects, based on how do they match the query. An object would match the query 100% if it contains all properties in the query.
My program ...
3
votes
1
answer
429
views
LeetCode: Minimum cost to hire k workers
https://leetcode.com/problems/minimum-cost-to-hire-k-workers/
There are N workers. The i-th worker has a quality[i] and a minimum
wage expectation wage[i].
Now we want to hire exactly K workers to ...
4
votes
1
answer
147
views
Overriding List subscription to create IndexedHeap for Classical Dijkstra's Algorithm
Much of the academic exposition of Dijkstra's Algorithm (such as Wikipedia, or this class page from Darmouth) relies on your priority queue having the ability decrease the key of an entry: the ...
0
votes
2
answers
195
views
A simple card game simulator
This is a homework question, and I have written the code but wasn't sure if I had picked the right data structure for this job and minimised time complexity. Can anyone give me some feedback, anything ...
3
votes
1
answer
629
views
C# binary heap priority queue
I made an A* pathfinder and it was too slow so i did some research into priority queues, i got it working but i am wondering if there is any improvements i can make for this class.
I opted to make a ...
1
vote
2
answers
3k
views
Generic Min Heap Implementation in Java
There is a Min-Heap implementation in Java. BubbleUp() and BubbleDown() could have been coded using recursion but I prefer without recursion. Would there be a major difference if had used recursion? ...
10
votes
1
answer
360
views
Yet Another MinHeap
So, this has been done quite a few times on here, but each of the linked implementations has some significant issues. Since I needed a MinHeap anyway, I figured I would throw my version into the ring.
...
12
votes
3
answers
7k
views
Priority Queues - Array based implementation
I am learning about stacks, queues, lists & hash tables from the book Data Structures using C and C++ by Tanenbaum. I am also spending time to take in OOPs essentials, to ensure they sink in well, ...
2
votes
0
answers
199
views
An ISeq implementing Priority Queue
This is a follow up to my last review request.
I made three major changes:
I had it fully implement ISeq and IPersistentStack, ...
2
votes
0
answers
134
views
A Priority Queue implemented using a Linked List
I'm going to write a Huffman Coding implementation, and decided to write from scratch a priority queue to help out. I've never written a priority queue before, in any language, so this was interesting....
0
votes
1
answer
139
views
Setup ordering in priority blocking queue
I have a PriorityBlockingQueue in which I am adding SocketHolder. And let's say current datacenter where this code is running is ...
4
votes
1
answer
1k
views
Priority queue implementation in C based on heap ordered (resizable) array - take 2
You think that your code is perfect ... until you put it up for code review.
I put up my priority queue for review and received lots of really good feedback. Including a memory leak which was ...
4
votes
4
answers
3k
views
Priority queue implementation in C based on heap ordered (resizable) array
I am practicing writing C library code and wrote a priority queue for some graph work.
I am fairly new to writing C libraries so would appreciate any feedback on this implementation.
Some items to ...
6
votes
2
answers
2k
views
A stable priority queue in C++
I have this priority queue in C++ that is stable. Stability here means that if the queue contains different elements with equal priority, they will be popped in the insertion order.
...
3
votes
4
answers
12k
views
Most frequent word in an array of strings - Java
Input word array is
...
1
vote
1
answer
390
views
Binary heap (priority queue) implementation in JavaScript
I wrote this heap implementation because I need it to run Dijkstra's algorithm to find paths in a game (for which reason I'd like this implementation not to be unreasonably slow...)
Sadly I don't ...
1
vote
1
answer
423
views
Priority queue in Erlang
I'm new to Erlang and I'm trying to port my Project Euler solutions in C# to Erlang. I have a priority queue implementation with unit tests.
I'm wondering if I'm missing something(I probably do) if ...
6
votes
0
answers
2k
views
Fibonacci heap in Python
I have this implementation of the Fibonacci heap in Python:
...
2
votes
1
answer
2k
views
Minimum Priority Queue implementation in Kotlin
Below you can find a generic implementation and some unit tests of a minimum priority queue in Kotlin.
What could be improved in this implementation, so that it complies to best coding practices in ...
4
votes
1
answer
15k
views
Huffman Coding in C++
I have written this code after studying from Introduction to Algorithm and from GeeksForGeeks. I know there is a lot to improve because I don't know much C++11. Please help me to improve this code.
<...
1
vote
1
answer
760
views
Template heap/priority-queue data structure with update-key operation
I implemented the following priority-queue/heap with an update-key operation. The update key uses the map from STL, which still requires lg(n) time for lookup. ...
4
votes
2
answers
3k
views
Maximum Priority Queue using Heap
I have written this program for Maximim Priority Queue after studying from Introduction to Algorithm . I want to improve my code. Is there any other method to implement Priority Queue instead of Heap?
...
0
votes
2
answers
2k
views
Minimum priority queue using Singly Linked LIst
I have written this code for Priority Queue using Singly Linked List. I want to improve this code. Is there any other method to write program for priority queue?
...
2
votes
1
answer
3k
views
Implementation of Prim's Algorithm to find minimum spanning tree
What is the time complexity of the following code? I'm implementing Prim's Algorithm with adjacency matrix representation of the graph and priority queue.
...
1
vote
1
answer
12k
views
Priority in pair<int,int> inside priority_queue on basis of both elements [closed]
I want a priority queue such that first it should be done on basis of first element (increasing order)and when clash occurs then on basis of second element(decreasing order). I came up with the ...
5
votes
2
answers
526
views
Select top 2 employees based on Grade and Alphabetical Order
Given a list of Employees ( name and grade). Output the names of the top 2 employees selected for a task(sorted based on grade and then alphabetically).
I am using a maxHeap and override the ...
7
votes
1
answer
13k
views
Priority Queue with update-able values
Here is my attempt to implement a minimum priority queue class in Python using the heapq module. I plan to use it in graph search algorithms so the values ...
11
votes
2
answers
922
views
Java queue with dynamic priority flag
I need to build a queue where the elements will be added and removed in chronological order by default. But if the client sets the priority flag for the queue I need to be able to pull the elements ...
2
votes
0
answers
1k
views
Priority queue with updatable values
I'm writing a priority queue that stores a bunch of data with a value attached to the data, with \$O(1)\$ access to the data with the smallest value attached to it. I also need to be able to update ...
4
votes
2
answers
985
views
Basic generic priority queue using an unsorted list
I am aware that there are other ways of implementing a priority queue e.g. using a sorted array/list. Would appreciate some comments on my implementation of a basic priority queue supporting three ...
5
votes
1
answer
2k
views
Python priority queue class wrapper
I'm trying to incorporate the advice found in https://docs.python.org/3.5/library/heapq.html in order to make a priority queue implementation (see corresponding section) in a class ...