2022 Developer Survey is open! Take survey.

Questions tagged [priority-queue]

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

Filter by
Sorted by
Tagged with
4 votes
0 answers
49 views

d-ary heap in Perl

This is my the very first data structure written in Perl: ...
user avatar
  • 25.3k
2 votes
1 answer
49 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. ...
user avatar
  • 57
7 votes
2 answers
1k 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 ...
user avatar
1 vote
0 answers
39 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 ...
user avatar
3 votes
1 answer
63 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 ...
user avatar
  • 171
0 votes
1 answer
49 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 ...
user avatar
  • 41
2 votes
1 answer
242 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 ...
user avatar
8 votes
2 answers
498 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 ...
user avatar
2 votes
2 answers
216 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 ...
user avatar
  • 135
4 votes
2 answers
170 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 ...
user avatar
1 vote
0 answers
42 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, ...
user avatar
5 votes
1 answer
106 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 ...
user avatar
  • 161
2 votes
1 answer
99 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 ...
user avatar
2 votes
1 answer
654 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 ...
user avatar
  • 25.3k
2 votes
1 answer
225 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. ...
user avatar
2 votes
1 answer
191 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 ...
user avatar
3 votes
1 answer
352 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 ...
user avatar
  • 5,249
4 votes
1 answer
104 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 ...
user avatar
0 votes
2 answers
127 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 ...
user avatar
3 votes
1 answer
516 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 ...
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? ...
user avatar
10 votes
1 answer
326 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. ...
user avatar
12 votes
3 answers
6k 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, ...
user avatar
  • 335
2 votes
0 answers
134 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, ...
user avatar
2 votes
0 answers
93 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....
user avatar
0 votes
1 answer
109 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 ...
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 ...
user avatar
  • 2,227
4 votes
4 answers
2k 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 ...
user avatar
  • 2,227
1 vote
0 answers
113 views

Sorted set a Queue

I needed a data structure offering both poll returning the smallest element and fast contains. A ...
user avatar
  • 13.4k
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. ...
user avatar
  • 25.3k
3 votes
4 answers
11k views

Most frequent word in an array of strings - Java

Input word array is ...
user avatar
1 vote
0 answers
491 views

Efficient stable priority queue in Java

I have this stable priority queue. It runs all the operations within \$\mathcal{O}(\log P)\$, where \$P\$ is the number of distinct priority keys (which may be smaller than the number of elements ...
user avatar
  • 25.3k
1 vote
1 answer
339 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 ...
user avatar
  • 571
1 vote
1 answer
308 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 ...
user avatar
5 votes
0 answers
2k views

Fibonacci heap in Python

I have this implementation of the Fibonacci heap in Python: ...
user avatar
  • 25.3k
1 vote
0 answers
164 views

Purely functional octree and octree priority queue

I'm programming a game in Scala, and a lot of tasks are able to be done in the background. I've created a system in which each Future can be assigned a position in 3d space, and they are stored in an ...
user avatar
  • 267
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 ...
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. <...
user avatar
  • 2,439
1 vote
1 answer
605 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. ...
user avatar
  • 119
1 vote
0 answers
582 views

Minimum Priority Queue using Heap

After getting suggestions for Maximum Priority Queue I have written program for Minimum Priority Queue. Help me improve this code. ...
user avatar
  • 2,439
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? ...
user avatar
  • 2,439
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? ...
user avatar
  • 2,439
2 votes
1 answer
2k 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. ...
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 ...
user avatar
  • 13
5 votes
2 answers
482 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 ...
user avatar
7 votes
1 answer
11k 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 ...
user avatar
  • 73
11 votes
2 answers
733 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 ...
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 ...
user avatar
  • 83
4 votes
2 answers
943 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 ...
user avatar
5 votes
1 answer
1k 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 ...
user avatar
  • 297