People who code: we want your input. Take the Survey

# Questions tagged [priority-queue]

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

67 questions
Filter by
Sorted by
Tagged with
2answers
489 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 ...
2answers
110 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 ...
2answers
116 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 ...
0answers
32 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, ...
1answer
86 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 ...
1answer
3k views

### C++ Heap implementation

I'm on my way of understanding basic data structures and sorting algorithms through implementing them in c++. Post is followed of my implementation of Vector. I decided to weld the heap behaviour ...
1answer
88 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 ...
1answer
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. <...
1answer
472 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 ...
1answer
142 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. ...
1answer
162 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 ...
1answer
316 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 ...
1answer
103 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 ...
2answers
110 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 ...
1answer
453 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 ...
1answer
10k 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 ...
2answers
2k 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? ...
1answer
314 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. ...
1answer
306 views

### Updatable priority queue

This is an updatable priority queue. In contains an index (implemented as std::unordered_map) which maps a value to its position in the queue itself. The queue is ...
3answers
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, ...
0answers
111 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, ...
0answers
79 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....
1answer
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 ...
1answer
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 ...
4answers
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 ...
0answers
104 views

### Sorted set a Queue

I needed a data structure offering both poll returning the smallest element and fast contains. A ...
1answer
326 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 ...
2answers
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. ...
4answers
11k views

### Most frequent word in an array of strings - Java

Input word array is ...
0answers
447 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 ...
1answer
255 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 ...
0answers
1k views

### Fibonacci heap in Python

I have this implementation of the Fibonacci heap in Python: ...
0answers
101 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 ...
1answer
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 ...
1answer
572 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. ...
0answers
575 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. ...
2answers
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? ...
2answers
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? ...
1answer
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. ...
1answer
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 ...
2answers
478 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 ...
1answer
754 views

### Node comparison using priority queue for Dijkstra's Shortest Path Algorithm

Instead of using a MinHeap that will allow me to change the vertex priorities I am using the Java library PriorityQueue. Here ...
3answers
2k views

### Indexed Fibonacci heap implementation

I implemented two versions of a Fibonacci heap one using a unordered map (mapping keys to their nodes) so that the client can call decrease in $O(1)$ average and ...
2answers
627 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 ...
0answers
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 ...
2answers
931 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 ...
1answer
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 ...
1answer
2k views

### Priority queue implementation using unsorted and sorted array

Below is the unsorted array and sorted array implementation of priority queue. Code directory structure: ...
1answer
258 views

### Dijkstra's Algorithm not optimized enough

I was attempting a question on HackerRank-Dijkstra's Shortest Reach 2 and upon submission my programs times out in 3/7 test cases. One of the test cases had 200 nodes and about 2000 connections. Here ...
4answers
7k views

### Priority queue implementation in C#

My application has a thread for handling database inserts and updates. Data is added by other threads to a generic queue in the DB thread. The contents of this queue is retrieved and is sequentially ...