Skip to main content

Questions tagged [priority-queue]

Priority queues are dynamic sets that always remove highest priority elements first.

Filter by
Sorted by
Tagged with
3 votes
0 answers
71 views

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 ...
Khải Nguyễn Danh's user avatar
3 votes
1 answer
148 views

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 ...
jzhu379's user avatar
  • 31
5 votes
0 answers
117 views

(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 ...
coderodde's user avatar
  • 32.3k
3 votes
1 answer
179 views

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 ...
Programmer's user avatar
7 votes
2 answers
454 views

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 ...
FreezePhoenix's user avatar
5 votes
1 answer
110 views

This is my very first data structure written in Perl for a d-ary heap: ...
coderodde's user avatar
  • 32.3k
2 votes
1 answer
125 views

So, I needed a priority queue for D* lite and I wanted to know whether this is an acceptable implementation or not. ...
a a's user avatar
  • 157
6 votes
2 answers
4k views

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 ...
user1429322's user avatar
2 votes
0 answers
317 views

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 ...
Caleb Moore's user avatar
2 votes
1 answer
277 views

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 ...
Someone's user avatar
  • 161
1 vote
1 answer
94 views

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 ...
MPC's user avatar
  • 61
2 votes
1 answer
975 views

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 ...
Souvik Ghosh's user avatar
8 votes
2 answers
589 views

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 ...
Tennis Tubbies's user avatar
2 votes
2 answers
557 views

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 ...
Bogdasar's user avatar
  • 235
4 votes
2 answers
218 views

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 ...
Steven Aguilar's user avatar
6 votes
1 answer
180 views

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 ...
xrfxlp's user avatar
  • 191
2 votes
1 answer
242 views

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 ...
YongHyun Kwon's user avatar
2 votes
1 answer
838 views

Now I have this very simple priority queue. add and changePriority both run in \$\mathcal{O}(n)\$ and ...
coderodde's user avatar
  • 32.3k
2 votes
1 answer
424 views

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. ...
Omri Shneor's user avatar
2 votes
1 answer
275 views

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 ...
user3371223's user avatar
3 votes
1 answer
429 views

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 ...
Gilad's user avatar
  • 5,443
4 votes
1 answer
147 views

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 ...
user513093's user avatar
0 votes
2 answers
195 views

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 ...
Prashin Jeevaganth's user avatar
3 votes
1 answer
629 views

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 ...
WDUK's user avatar
  • 247
1 vote
2 answers
3k views

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? ...
Hamidur Rahman's user avatar
10 votes
1 answer
360 views

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. ...
Jason Watkins's user avatar
12 votes
3 answers
7k views

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, ...
Quasar's user avatar
  • 639
2 votes
0 answers
199 views

This is a follow up to my last review request. I made three major changes: I had it fully implement ISeq and IPersistentStack, ...
Carcigenicate's user avatar
2 votes
0 answers
134 views

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....
Carcigenicate's user avatar
0 votes
1 answer
139 views

I have a PriorityBlockingQueue in which I am adding SocketHolder. And let's say current datacenter where this code is running is ...
user1950349's user avatar
4 votes
1 answer
1k views

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 ...
arcomber's user avatar
  • 2,551
4 votes
4 answers
3k views

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 ...
arcomber's user avatar
  • 2,551
6 votes
2 answers
2k views

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. ...
coderodde's user avatar
  • 32.3k
3 votes
4 answers
12k views

Input word array is ...
kunal saxena's user avatar
1 vote
1 answer
390 views

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 ...
gaazkam's user avatar
  • 581
1 vote
1 answer
423 views

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 ...
Ufuk Hacıoğulları's user avatar
6 votes
0 answers
2k views

I have this implementation of the Fibonacci heap in Python: ...
coderodde's user avatar
  • 32.3k
2 votes
1 answer
2k views

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 ...
gil.fernandes's user avatar
4 votes
1 answer
15k views

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. <...
coder's user avatar
  • 2,471
1 vote
1 answer
760 views

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. ...
alexwest's user avatar
  • 119
4 votes
2 answers
3k views

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? ...
coder's user avatar
  • 2,471
0 votes
2 answers
2k views

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? ...
coder's user avatar
  • 2,471
2 votes
1 answer
3k views

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. ...
QuestionEverything's user avatar
1 vote
1 answer
12k views

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 ...
Bash's user avatar
  • 13
5 votes
2 answers
526 views

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 ...
DntFrgtDSemiCln's user avatar
7 votes
1 answer
13k views

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 ...
hakeem's user avatar
  • 73
11 votes
2 answers
922 views

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 ...
dissatisfiedprogrammer's user avatar
2 votes
0 answers
1k views

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 ...
Rch's user avatar
  • 83
4 votes
2 answers
985 views

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 ...
dragonfly02's user avatar
5 votes
1 answer
2k views

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 ...
Sorrop's user avatar
  • 307