queue has front and rearand items are removed from the front howeverin priority queueitems are ordered by key valueso that the item with the lowest key (or in some implementations the highest keyis always at the front items are inserted in the proper position to maintain the order here' how the mail sorting analogy applies to priority queue every time the postman hands you letteryou insert it into your pile of pending letters according to its priority if it must be answered immediately (the phone company is about to disconnect your modem line)it goes on topwhile if it can wait for leisurely answer ( letter from your aunt mabel)it goes on the bottom when you have time to answer your mailyou start by taking the letter off the top (the front of the queue)thus ensuring that the most important letters are answered first this is shown in figure like stacks and queuespriority queues are often used as programmer' tools we'll see one used in finding something called minimum spanning tree for graphin "weighted graphs figure letters in priority queue alsolike ordinary queuespriority queues are used in various ways in certain computer systems in preemptive multitasking operating systemfor exampleprograms may be placed in priority queue so the highest-priority program is the next one to receive time-slice that allows it to execute in many situations you want access to the item with the lowest key value (which might represent the cheapest or shortest way to do somethingthus the item with the smallest key has the highest priority somewhat arbitrarilywe'll assume that' the case in this discussionalthough there are other situations in which the highest key has the highest priority besides providing quick access to the item with the smallest keyyou also want priority queue to provide fairly quick insertion for this reasonpriority queues areas we noted earlieroften implemented with data structure called heap we'll look at heaps in in this we'll show priority queue implemented by simple array this implementation suffers from slow insertionbut it' simpler and is appropriate when the number of items isn' high or insertion speed isn' critical the priorityq workshop applet