Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [priority-queue]

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

Filter by
Sorted by
Tagged with
5 votes
0 answers
83 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 ...
coderodde's user avatar
  • 28.4k
3 votes
1 answer
128 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 ...
Programmer's user avatar
7 votes
2 answers
378 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 ...
FreezePhoenix's user avatar
1 vote
0 answers
165 views

Priority Queue implementation using a Heap [closed]

I'm working on a custom implementation of A-Star and so I had to also create a Priority Queue and so I had to create a Heap. I'm quite happy with my Heap but I'm a bit worried about my Priority Queue: ...
Caïn's user avatar
  • 111
5 votes
1 answer
82 views

Bidirectional Dijkstra d-ary heap

This is my very first data structure written in Perl for a d-ary heap: ...
coderodde's user avatar
  • 28.4k
2 votes
1 answer
107 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. ...
a a's user avatar
  • 157
6 votes
2 answers
3k 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 ...
user1429322's user avatar
2 votes
0 answers
286 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 ...
Caleb Moore's user avatar
2 votes
1 answer
247 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 ...
Someone's user avatar
  • 161
0 votes
1 answer
70 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 ...
MPC's user avatar
  • 41
2 votes
1 answer
915 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 ...
Souvik Ghosh's user avatar
8 votes
2 answers
520 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 ...
Tennis Tubbies's user avatar
2 votes
2 answers
529 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 ...
Bogdasar's user avatar
  • 135
4 votes
2 answers
190 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 ...
Steven Aguilar's user avatar
1 vote
0 answers
125 views

Making a priority queue using a Heap. Without using queue or heapq

I have to implement a priority queue using a heap without any library / package for priority queue or heap. I made a BinHeap class which is a min heap, and I made a priority queue class with enqueque, ...
lastìada's user avatar
5 votes
1 answer
152 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 ...
xrfxlp's user avatar
  • 161
2 votes
1 answer
223 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 ...
YongHyun Kwon's user avatar
2 votes
1 answer
822 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 ...
coderodde's user avatar
  • 28.4k
2 votes
1 answer
401 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. ...
Omri Shneor's user avatar
2 votes
1 answer
259 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 ...
user3371223's user avatar
3 votes
1 answer
403 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 ...
Gilad's user avatar
  • 5,311
4 votes
1 answer
115 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 ...
user513093's user avatar
0 votes
2 answers
163 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 ...
Prashin Jeevaganth's user avatar
3 votes
1 answer
597 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 ...
WDUK's user avatar
  • 247
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? ...
Hamidur Rahman's user avatar
10 votes
1 answer
331 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. ...
Jason Watkins's user avatar
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, ...
Quasar's user avatar
  • 335
2 votes
0 answers
170 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, ...
Carcigenicate's user avatar
2 votes
0 answers
113 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....
Carcigenicate's user avatar
0 votes
1 answer
118 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 ...
user1950349's user avatar
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 ...
arcomber's user avatar
  • 2,449
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 ...
arcomber's user avatar
  • 2,449
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. ...
coderodde's user avatar
  • 28.4k
3 votes
4 answers
12k views

Most frequent word in an array of strings - Java

Input word array is ...
kunal saxena's user avatar
1 vote
1 answer
367 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 ...
gaazkam's user avatar
  • 561
1 vote
1 answer
393 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 ...
Ufuk Hacıoğulları's user avatar
6 votes
0 answers
2k views

Fibonacci heap in Python

I have this implementation of the Fibonacci heap in Python: ...
coderodde's user avatar
  • 28.4k
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 ...
gil.fernandes's user avatar
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. <...
coder's user avatar
  • 2,449
1 vote
1 answer
729 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. ...
alexwest's user avatar
  • 119
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? ...
coder's user avatar
  • 2,449
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? ...
coder's user avatar
  • 2,449
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. ...
QuestionEverything's user avatar
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 ...
Bash's user avatar
  • 13
5 votes
2 answers
495 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 ...
DntFrgtDSemiCln's user avatar
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 ...
hakeem's user avatar
  • 73
11 votes
2 answers
869 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 ...
dissatisfiedprogrammer's user avatar
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 ...
Rch's user avatar
  • 83
4 votes
2 answers
966 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 ...
dragonfly02's user avatar
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 ...
Sorrop's user avatar
  • 297