Questions tagged [priority-queues]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
-3 votes
1 answer
94 views

Can you simulate the following process in $O(N.log N)$

Given an array $A[]$ of N integers. pseudocode: Traverse from left to right of this array. Let's say you are standing at index $j$. For each index i=1 to i=j-1, increment all $A[i]$ by $1$ if and ...
sibillalazzerini's user avatar
0 votes
0 answers
14 views

M/G/1 (?) with server vacations

I'm asking your help to solve this: Consider a time-division multiplexor that multiplexes $30$ input packet streams onto a outgoing link with a slot time of $4 \mu s$. Assume that the packet arrival ...
Alex_DeLarge's user avatar
0 votes
0 answers
35 views

M/M/1 priority queueing system (?), an exercise

can someone help me please solving this? Consider a switch with two input links and one outgoing transmission link. Data packets arrive at the first input link according to a Poisson process with mean ...
Alex_DeLarge's user avatar
1 vote
2 answers
161 views

How can we prove that "extract almost minimum" operation in a priority queue cannot be done in o(log n)?

Suppose we want to create a priority queue with 2 operations: insert and extract almost min. Extract almost min operation selects either the first minimum or a second minimum item from the structure ...
JsonResponse's user avatar
0 votes
1 answer
73 views

Looking for name of a priority queue data structure based on bit-boundary buckets

(Note: cross-listed on stack overflow: https://stackoverflow.com/questions/73362856/looking-for-name-of-a-priority-queue-data-structure-based-on-bit-boundary-bucket) I'm looking for the name of a data ...
Craig Gidney's user avatar
  • 5,802
0 votes
1 answer
326 views

Does order of elements in a set matter in Dijkstra's Algorithm?

When we use a set for doing Dijkstra's Algorithm, we use a pair of {distance,node} which we insert in a set. Most of the articles say that the first element of pair should be the distance , else we ...
Rasmus IN's user avatar
0 votes
1 answer
134 views

Did I invent a new data structure?

I needed to implement a priority queue for a project I'm working on and had this idea. In a priority queue BST implementation wouldn't it be more efficient if the poll node pointed to its parent since ...
Abdulmalek Almkainzi's user avatar
1 vote
0 answers
72 views

Priority Queues with $DecreaseKey,FindMin,Insert$ in time $O(1)$, $DeleteMin$ in $ O(\log n)$ and $IncreaseKey$ in $O(1)$, Amortized

Problem: In this problem, we discuss Data-Structures that maintain a group of ordered elements. We must support the operations $ DecreaseKey, FindMin, Insert $ in time $ O(1) $ and the operation $ ...
flamel12's user avatar
  • 233
2 votes
1 answer
862 views

What is the amortized cost of pulling top K elements from a priority queue?

To pop an element off of a priority queue, the worst-case complexity is: O(logN) where N is the number of elements. Now if you do K pop operations on the priority ...
Aditya's user avatar
  • 115
10 votes
1 answer
3k views

Would it make sense to use an array of linked lists for a Priority Queue, given a fixed number of priorities?

From what I can gather priority queues are typically implemented with heaps. If I have a small fixed number of priorities (such as 4), wouldn't a small array where each index represents the priority, ...
user4779's user avatar
  • 371
4 votes
0 answers
146 views

Does a priority queue exist with O(1) extract-min and re-insertion from removed positions?

I am envisioning a priority queue that is a bit strange. It represents wanting to do a depth-first left-to-right walk of a tree, but allowing for parallel workers where there can be time between ...
orlp's user avatar
  • 12.7k
1 vote
1 answer
526 views

Indexed Priority Queue change key

So I was just studying about Indexed Priority Queues and I got confused about the increase key operation. So basically we have the option to increase a key for an element in log n time because we can ...
Gopalakrishnan Ganesan's user avatar
2 votes
0 answers
36 views

Is there a review of lock free priority queues for single consumer multiple producer?

Background The task I have at hand is to write an event scheduler. From what I understood, it is basically a priority queue which needs to support concurrent insertions and single threaded delete ...
Incomputable's user avatar
3 votes
1 answer
202 views

Designing a Queue that efficiently tracks position

Suppose we want to construct a queue with the following properties: The priority of each member of the queue must be known. For example, for the head node, their priority is 1, for the next node, ...
Newb's user avatar
  • 314
2 votes
2 answers
183 views

If both could be implemented with the other, what are the differences between priority queues and binary heaps?

I've red that a binary heap can be implemented using a priority queue. I've also red the opposite, that a priority queue can be implemented using a binary heap. This seems strange to me as ...
northerner's user avatar
3 votes
1 answer
68 views

What is the analysis that a heap's optimal branching factor is between 2 and 5?

I'm reading the book Advanced Algorithms and Data Structures. It makes the claim that the optimal branching factor $D$ for a heap satisfies $2 \le D \le 5$, and that it is most likely $3$ or $4$ ...
Andrew's user avatar
  • 131
2 votes
2 answers
638 views

Given n positive integers, pick two elements and subtract each by one with one operation. Find maximum number of operations

Problem Description: We have an array of $n$ positive integers and in one operation we have to choose two elements in the array and decrease them by $1$. (Elements on which we are performing this ...
Poojan's user avatar
  • 21
0 votes
1 answer
387 views

Build a priority queue using dictionary

QUESTION: Can we Implementing priority queue with hash table please? As I understand, dictionary/hash table does not have sorting mechanism inside. It adds pairs of $<key,value>$ to hash table. ...
Avv's user avatar
  • 493
2 votes
1 answer
551 views

Dijkstra's Algorithm Same Node Added Multiple Times to Priority Queue

In the this discussion of Dijkstra's Algorithm appear the following comments: ...
Robin Andrews's user avatar
1 vote
1 answer
93 views

Minimum time to finish all meetings

what algorithm would you use to solve this problem which I recently faced in an interview? There's a council where people go to have meetings. A person comes at time x and needs to be in a meeting for ...
Martin's user avatar
  • 111
0 votes
0 answers
27 views

How to find diffrenet ways to implement merge and delete_min operation in binomial heap?

I have searched on the internet to find different ways to learn binomial heap operations. What I have found is not quite helpful for me.For example, for delete min operation the algorithm says: ...
Mahmut Salman's user avatar
1 vote
2 answers
222 views

Max-Heap PriorityQueue to keep the k highest items and return them in descending order

I have created a custom implementation for PriorityQueue using max-heap and everything works fine. But now i want to change it and keep only the k highest objects in the heap after every insertion. I ...
Theo Giannakopoulos's user avatar
2 votes
1 answer
637 views

Is there an algorithm for random sampling from a priority queue with probability proportional to priority?

Suppose I want to randomly sample from a large set of items, each of which has a "score". I want my probability of sampling to be proportional to the score. One simple way to achieve this ...
Cory Nezin's user avatar
0 votes
0 answers
39 views

data structure Q with priotry queue which allow us to find the median in $O(1)$ and the data structure need to support the following operations

I've got this question from an exercise and i'm not sure if it is possible to do so Think of new data structure Q with priotry queue which allow us to find the median in $O(1)$ and the data structure ...
convxy's user avatar
  • 211
3 votes
2 answers
765 views

What are the disadvantages of Fibonacci Heaps?

A Fibonacci heap is a data structure for priority queue / heap operations. It seems to have the best complexity for all operations: Since it has the best performance, why not use it everywhere? What ...
huang's user avatar
  • 143
1 vote
1 answer
49 views

Constructing a data structure supporting prioritized key lookup

so this is more or less a shot in the dark as I am feeling stuck. Maybe some of you have an idea which helps. Here is the problem description (pseudo formal): I want to have a structure $T = \{ \hat{...
milck's user avatar
  • 111
0 votes
0 answers
618 views

Monotone priority queues

I'm a little confused about how monotone priority queues work. As far as I understand: A queue is a FIFO data structure A priority queue is a queue where the current element of highest (or lowest) ...
Amelio Vazquez-Reina's user avatar
3 votes
2 answers
934 views

Implementing an efficent priority queue using only stacks

Is it possible to implement an efficient priority queue (as efficient as a heap) only using the stack data structure? The usual efficiency for a priority queue which is implemented using a heap is : ...
Command Master's user avatar
1 vote
1 answer
343 views

Priority Queue Using Stack

Can one build a priority queue using stacks, such that the priority queue has the same complexity for each operation. Could it be done? If so how? If not what is the best solution that can be done? ...
newhere's user avatar
  • 101
1 vote
1 answer
140 views

Numerical Accuracy & Sorting Algorithms?

Sedgewick and Wayne talk about how sorting algorithms and, specifically, priority queues are used in devising ways to improve accuracy in floating-point calculations: https://algs4.cs.princeton.edu/...
KingCodeFish's user avatar
1 vote
0 answers
26 views

How to compute the general term formula for the number of full binary tree heaps that can be formed with distinct elements?

The number of possible heaps that are full binary trees of height $h$ and can be formed with ($n = 2^h - 1$) distinct elements can be computed by recursion: $$ a_h = {2^h - 2 \choose 2^{h - 1} - 1} a_{...
Shreck Ye's user avatar
  • 145
4 votes
1 answer
2k views

Dijkstra without decrease key

I was reading through this paper, "Priority Queues and Dijkstra's Algorithm" by Mo Chen et al., which suggests using Dijkstra's without edge relaxation, but to rather to just insert new ...
user3726947's user avatar
3 votes
0 answers
569 views

Making an array increasing by modifying elements

I am trying to solve a problem on codeforces. Given an integer array $a_1,\ldots,a_n$, our goal is to find the minimal number of instructions, each of which increments or decrements a single entry, ...
nitangle's user avatar
2 votes
2 answers
608 views

Why can't we replace Dijkstra's priority queue with a regular queue?

I am confused why we can't simply use a normal queue instead of a priority queue for Dijkstra's. I agree that you can find the shortest path in fewer iterations of the while loop using a priority ...
A. Akella's user avatar
3 votes
1 answer
49 views

Parallelization of priority queue-based algorithms

There's a number of algorithms that operate by maintaining and consuming a priority queue of "events". I'm thinking primarily of geometric algorithms, particularly sweep-line algorithms like Bentley-...
Sneftel's user avatar
  • 221
0 votes
2 answers
221 views

When inserting an element in a priority queue and the heap size is already at max capacity, should you output an error OR increase the array size?

I'm currently learning about how to implement priority queues using heaps, but I've hit a wall while trying to implement the insertion operation. Assume that the size of the array storing the ...
Johan von Adden's user avatar
1 vote
1 answer
120 views

Priority queue with a buffer for delayed insertion and other tweaks

I was thinking of ways to optimise a (heap-based) priority queue in certain scenarios, like in best-first path search algorithms (Dijkstra, A*, etc.). One possible optimisation is to delay insertions ...
Alexey's user avatar
  • 251
0 votes
1 answer
89 views

Short Fibonacci Heap

Is it possible to create a Fibonacci Heap that has exactly 5 nodes: one root node and 4 children of that root?. If yes please explain the sequence of operations to do so. If it is not possible then ...
Anuj Mittal's user avatar
1 vote
1 answer
109 views

An algorithm to drop low-priority items from a heap-based priority queue

I am looking for an efficient algorithm to drop from a complete binary min heap all items whose weight exceeds a given value. (Or, equivalently, to drop from a priority queue realised by such a heap ...
Alexey's user avatar
  • 251
3 votes
3 answers
958 views

Merging balls interview problem

Here is an interview problem about balls rolling towards buckets from Sprinklr Interview Experience at GeekforGeeks. You are given $n$ balls on the table and all the balls are rolling towards the ...
Manoharsinh Rana's user avatar
1 vote
1 answer
94 views

Heap operating in time $\Gamma^{-1}(n)^2$

I have a priority queue implementation which I claim has the following worst case asymptotic run-times for the given operations: PEEK_MIN …………………………… O(1) POP_MIN…………………………… O( (INVERSE_Γ(n)) ^2). ...
Toothpick Anemone's user avatar
1 vote
2 answers
543 views

Is there a name for this priority queue data structure?

While watching a sports tournament, I noticed that the tournament tree looks a lot like a heap. I came up with the following data structure: A complete binary tree where the leaves are elements of ...
wlad's user avatar
  • 479
3 votes
2 answers
2k views

Why is a heap better than a linked list for implementation of a priority queue?

Using a heap, you have O(log(n)) insertion and O(log(n)) removal. Using a linked list, you have O(n) insertion and O(1) removal. Why is it better to have log-n for both than n for one and constant ...
temporary_user_name's user avatar
1 vote
0 answers
115 views

How priority queue is used in Dijsktra algorithm?

I have difficulties understanding how the priority queue is used in Dijkstra algorithm. Wikipedia lists 3 operations performed on priority queue: add_with_priority(), extract_min(), ...
greenoldman's user avatar
1 vote
2 answers
302 views

Sorting in a Priority Queue

Does a priority queue Queue<K,V> always sort its elements based on the value of each element or its key? I know than the priority in the queue is based on ...
user avatar
1 vote
1 answer
71 views

Complexity of closest set of points in plane problem

Given a set of points on a plane find the set of $n$ points that are closest to the origin. (Points are pairs of integers.) Input: list of points. Initialize a priority queue $Q$, where ...
lucidquiet's user avatar
1 vote
2 answers
189 views

Priority queue of constant size fit for extraction of K highest priority elements

In an algorithm I'm designing, I need to do this cycle on a priority queue of constant size N many times, as quickly as possible: get $K$ highest priority elements (do on them some outside ...
Rotem Shalev's user avatar
2 votes
0 answers
531 views

How would a priority queue be implemented in a functional programming language?

How would a priority queue be coded efficiently in a functional programming language? I'm new to functional programming, but I'm having difficulty understanding how a data structure that seems to ...
Alecto Irene Perez's user avatar
1 vote
3 answers
2k views

Correct term for a priority queue with unique elements

Is there a standard term for a priority queue which can only hold a single occurrence of any element? This would be a priority queue for which operations such as "raise the priority of element ...
Alexey's user avatar
  • 251
1 vote
1 answer
232 views

Leftist Tree initialization in O(n) time

In the book Handbook of Data Structures and Applications, section 5.2.5, (copy of the relevant section available here) about leftist queues, the author(s) state the following: For the complexity ...
NMR-3's user avatar
  • 13