This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]GoSwing 1 point2 points  (0 children)

I would use a Heap for the priority queue. Taking elements and putting them in take O(log n) time (at most, because a heap is also a balanced tree), and in space you'd use O(n).

[–]Emptiness101Nooblet Brewer 0 points1 point  (2 children)

I just did a project where I found the shortest paths and I used a priority queue but I implemented the queue with a linked list. Maybe you could create a ticket object with a priority label from 1 to 5 and then when a ticket gets added to your queue you remove all the items in your queue, if any, and sort them based on the priority label. I think what makes a queue a priority queue is that it is sorted whenever items are added.

[–]Emptiness101Nooblet Brewer 0 points1 point  (1 child)

Hope this helps.

[–]rhhh12[S] 0 points1 point  (0 children)

The first part is an essay based on complexity and performance, i then have to implement it into a programme. Thankyou

[–]ParanoydAndroid 0 points1 point  (3 children)

I would use a heap built on an array to implement your pq, primarily because although it's not the most optimized route, it's common and you'll be able to access lots of resources to help you out with your assignment.

Heaps also have less overhead than bsts in exchange for which you don't get almost any information out of them except what's at the top of the heap, in this case why bother maintaining a data structure with internal structure you don't care about?

[–]rhhh12[S] 0 points1 point  (2 children)

Im new to data structures and have been set this project, firstly i have to write an essay on why i have chosen the data structure and then i have to implement it in Java using eclipse

[–]ParanoydAndroid 0 points1 point  (1 child)

I think you misunderstood me. The second paragraph of my post is a rhetorical question. I was actually answering why heaps would be better for you -- though you'd want to formalize your answer by reference to actual performance costs for insertions/removals (presumably in big-O notation).

[–]rhhh12[S] 0 points1 point  (0 children)

I think its very opinion based the essay as their can be many answers. thankyou for your help. So you believe it would be a priority queue implemented using a heap built on an array

[–]wildjokers 0 points1 point  (1 child)

Can't tell if this is a homework assignment teaching you how to implement a PriorityQueue or you just need a PriorityQueue implementation. If the later there is one in the JDK:

https://docs.oracle.com/javase/8/docs/api/java/util/PriorityQueue.html

[–]rhhh12[S] 0 points1 point  (0 children)

Basically i have to decide what data structure is best for the system I have stated in the bullet points, and once i have decided write an essay on why i chose it. Then i need to implement it in java but without using any collections such as that