PAL: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>Aight 2009
mNo edit summary
 
en>Chincoong
m updating Thailand's status
Line 1: Line 1:
<br><br>[http://Thedesignw.com/?document_srl=358255 thedesignw.com]Think in regards to the tools available, where you're, who you might be with, etc. You learn how to feel ugly and feel you're an outsider inside your own family. Each investment represents only a small percentage of the total value in the portfolio. You will get an independent fee-only financial advisor over the National Association of Personal Financial Advisors (NAPFA). Fox Business Network host John Stossel went in terms of to post in the blog, "If the government is able to dictate our diet, what's next.<br><br>Association between hypothyroidism and small intestinal bacterial overgrowth. To date, failed mortgages still continue to haunt JP Morgan Chase because SEC's recently issued subpoena was followed with a 2% drop inside the financial institute's shares of stocks. Writing that simply reminded me of the very important point. When properly taken, L-arginine can enhance testosterone availability, increase blood flow on the genital area, increase sperm count and motility, increase virility, and heighten sensitivity in the men and women.<br><br>You just might brighten the day associated with an employee who are able to then continue and have a better attitude using the next customer they greet. And prior to deciding to go anywhere near judging yourself for having these issues, remind yourself of the truth about humans: The majority in the folks on the earth struggle with this faulty wiring to many extent. Organic baby food must be prepared in the home from organic fruit and vegetables (and, if you happen to be comfortable with the source, meat products) selected by you. The world became more aware of child abuse issues inside the poorer sections from the world through this unique film. Whether you're getting office-Tiffin service or getting corporate catering, unless caterers knows about food safety it can be quite risky to own food made by them.<br><br>As the old saying goes, &#8220;actions speak louder than words. Upon your son or daughter's return, you pay attention to candy wrappers with pinholes, discoloration, or tears. The result is really a conflict between consumers and companies which erodes stockholder equity due to the risk linked to free-riding. So what is it that people highly sensitive people can learn how to live with.<br><br>If you receive healthier to get a while, the sinuses might not be a bother for any while, further confusing the problem. You can freeze bananas to generate baby food, freeze bananas for smoothies and freeze bananas for banana bread. Watch yourself much more stressful stiuations and you'll be able to see how your system sets you up for any headache later - the shoulders pullup and knot, the neck grows more rigid, the solar plexus tightens, and quite often the jaw clenches too. In Japan, however, in the Osaka supermarket I found some seriously intriquing, notable and weird food.<br><br>Also, he explains that MSG is used within the scientific world when labs need to make rats fat. When substitute your meals are returned, don't expect foods from a original selection list to generally be sent. The actual chemical process that creates photochemical smog starts off with primary pollution from factories and automobiles inside early morning hours. Some acid reflux symptoms are less obvious given that they mimic symptoms produced by other medical conditions.<br><br>"I think you're one of the most beautiful woman I ever knew. This may result in [http://support.luxmodels.com/entries/52241430-Things-To-Eat-To-Get-A-Cut-Awesome-A-Lose-Weight storing ginger root] bad physical health depression anxiety and unfortunately open the threshold to lower level entities (ie inhuman spirits) which will come around and wreak havoc in your life. These are a couple of simple ideas that could possibly be made very captivating by non-professional caterers, band. When you continue your vibrational levels high you are vibrating with a higher rate, your problems should go away or resolve so much quicker you could discover everything you thought would have been a problem was really only a small hurdle you overcome easily. The reason for keeping a food diary is always to let yourself know very well what goes inside your mouth every day of the week.<br><br>Bad information keeps getting transferred - over and over. They quite simply form the listing of worst very toxic ingredients in food items you are able to eat. Did the truth is a television commercial and feel the product was a total must. One patient told me shooting water into his vein got him high.<br><br>Keep a phone list handy coming from all family members and neighbors. Since they're smaller you might have  [http://icgsoftware.zendesk.com/entries/37992309-How-Are-Your-Kidneys-Over-Masturbation molly Drug] to store much more of them. Going to the bank to get a loan is usually the number one method to gain funding for starting a business. Dry socket will be the incredibly painful condition that occurs in the event the blood clot in the hole where your tooth once was breaks loose. Toxins through the environment, like pesticides, herbicides, PCBs, dioxins and metals like mercury, are acknowledged to disrupt the delicate balance of thyroid hormone 19,20.<br><br>Within weekly, another blog had listed this particular update with their blog, in that they were discussing exactly the same topic. The free-riding potential of clients only winds up hurting consumers inside the end. They would be the habits who have brought you the success you love it today. This revolution doesn't require consumers to fight for rights or stage a protest from the bureaucracy of Washington. Clicking the "See all" link will load a page with fifty of the top free i - Phone apps.
{{more footnotes|date=October 2013}}
In [[computer science]]/data structure, a '''priority queue''' is an [[abstract data type]] which is like a regular [[queue (data structure)|queue]] or [[stack (data structure)|stack]] data structure, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. If two elements have the same priority, they are served according to their order in the queue.
 
A priority queue is not a [[Heap (data structure)|heap]]. A priority queue is an abstract concept like "a list" or "a map"; just as a list can be implemented with a [[linked list]] or an [[Array data structure|array]], a priority queue can be implemented with a heap or a variety of other methods.
 
== Operations ==
 
A priority queue must at least support the following operations:
 
* ''insert_with_priority'': add an [[element (mathematics)|element]] to the [[Queue (data structure)|queue]] with an associated priority.
* ''pull_highest_priority_element'': remove the element from the queue that has the ''highest priority'', and return it.
*: This is also known as "''pop_element(Off)''", "''get_maximum_element''" or "''get_front(most)_element''".
*: Some conventions reverse the order of priorities, considering lower values to be higher priority, so this may also be known as "''get_minimum_element''", and is often referred to as "''get-min''" in the literature.
*: This may instead be specified as separate "''peek_at_highest_priority_element''" and "''delete_element''" functions, which can be combined to produce "''pull_highest_priority_element''".
 
In addition, ''[[Peek (data type operation)|peek]]'' (in this context often called ''find-max'' or ''find-min''), which returns the highest-priority element but does not modify the queue, is very frequently implemented, and nearly always executes in [[Big O notation|''O''(1)]] time. This operation and its ''O''(1) performance is crucial to many applications of priority queues.
 
More advanced implementations may support more complicated operations, such as ''pull_lowest_priority_element'', inspecting the first few highest- or lowest-priority elements, clearing the queue, clearing subsets of the queue, performing a batch insert, merging two or more queues into one, incrementing priority of any element, etc.
 
== Similarity to queues ==
 
One can imagine a priority queue as a modified [[queue (data structure)|queue]], but when one would get the next element off the queue, the highest-priority element is retrieved first.
 
* ''stack'' &ndash; elements are pulled in [[LIFO (computing)|last-in first-out]]-order (e.g., a stack of papers)
* ''queue'' &ndash; elements are pulled in [[first-in first-out]]-order (e.g., a line in a cafeteria)
 
Stacks and queues may be modeled as particular kinds of priority queues. In a stack, the priority of each inserted element is monotonically increasing; thus, the last element inserted is always the first retrieved. In a queue, the priority of each inserted element is monotonically decreasing; thus, the first element inserted is always the first retrieved.
 
== Implementation ==
 
=== Naive implementations ===
 
There are a variety of simple, usually inefficient, ways to implement a priority queue. They provide an analogy to help one understand what a priority queue is. For instance, one can keep all the elements in an unsorted list. Whenever the highest-priority element is requested, search through all elements for the one with the highest priority. (In [[big O notation|big ''O'' notation]]: ''O''(1) insertion time, ''O''(''n'') pull time due to search.)
 
=== Usual implementation ===
 
To improve performance, priority queues typically use a [[Heap (data structure)|heap]] as their backbone, giving ''O''(log ''n'') performance for inserts and removals, and ''O''(''n'') to build initially. Alternatively, when a [[self-balancing binary search tree]] is used, insertion and removal also take ''O''(log ''n'') time, although building trees from existing sequences of elements takes ''O''(''n'' log ''n'') time; this is typical where one might already have access to these data structures, such as with third-party or standard libraries.
 
Note that from a computational-complexity standpoint, priority queues are congruent to sorting algorithms. See [[priority queue#Equivalence_of_priority_queues_and_sorting_algorithms|the next section]] for how efficient sorting algorithms can create efficient priority queues.
 
There are several specialized [[heap (data structure)|heap]] [[data structures]] that either supply additional operations or outperform these approaches. The [[binary heap]] uses ''O''(log ''n'') time for both operations, but also allows queries of the element of highest priority without removing it in constant time. [[Binomial heap]]s add several more operations, but require ''O''(log ''n'') time for requests. [[Fibonacci heap]]s can insert elements, query the highest priority element, and increase an element's priority in [[amortized analysis|amortized]] constant time,<ref name="CLRS">[[Thomas H. Cormen]], [[Charles E. Leiserson]], [[Ronald L. Rivest]], and [[Clifford Stein]]. ''[[Introduction to Algorithms]]'', Second Edition. [[MIT Press]] and McGraw-Hill, 2001. ISBN 0-262-03293-7. Chapter 20: Fibonacci Heaps, pp.476&ndash;497. Third edition p518.</ref> though deletions are still ''O''(log ''n''). [[Brodal queue]]s can do this in worst-case constant time.
 
While relying on a heap is a common way to implement priority queues, for integer data, faster implementations exist. This can even apply to data types that have a finite range, such as floats:
 
* When the set of keys is {1, 2, ..., ''C''}, a [[van Emde Boas tree]] would support the ''[[minimum]]'', ''[[maximum]]'', ''insert'', ''delete'', ''search'', ''[[extract-min]]'', ''[[extract-max]]'', ''[[predecessor]]'' and ''[[successor (graph theory)|successor]]'' operations in ''O''(log log ''C'') time, but has a space cost for small queues of about ''O''(2<sup>''m''/2</sup>), where ''m'' is the number of bits in the priority value.<ref>P. van Emde Boas. Preserving order in a forest in less than logarithmic time. In ''Proceedings of the 16th Annual Symposium on Foundations of Computer Science'', pages 75-84. IEEE Computer Society, 1975.</ref>
* The [[Fusion tree]] algorithm by [[Michael Fredman|Fredman]] and Willard implements the ''minimum'' operation in ''O''(1) time and ''insert'' and ''extract-min'' operations in <math>O(\sqrt{\log n})</math> time.<ref>[[Michael Fredman|Michael L. Fredman]] and Dan E. Willard. Surpassing the information theoretic bound with fusion trees. ''Journal of Computer and System Sciences'', 48(3):533-551, 1994</ref>
 
For applications that do many "[[Peek (data type operation)|peek]]" operations for every "extract-min" operation, the time complexity for peek actions can be reduced to ''O''(1) in all tree and heap implementations by caching the highest priority element after every insertion and removal. For insertion, this adds at most a constant cost, since the newly inserted element is compared only to the previously cached minimum element. For deletion, this at most adds an additional "peek" cost, which is typically cheaper than the deletion cost, so overall time complexity is not significantly impacted.
 
== Equivalence of priority queues and sorting algorithms ==
 
=== Using a priority queue to sort ===
 
The [[operational semantics|semantics]] of priority queues naturally suggest a sorting method: insert all the elements to be sorted into a priority queue, and sequentially remove them; they will come out in sorted order. This is actually the procedure used by several [[sorting algorithm]]s, once the layer of [[abstraction (computer science)|abstraction]] provided by the priority queue is removed. This sorting method is equivalent to the following sorting algorithms:
 
* [[Heapsort]] if the priority queue is implemented with a heap.
* [[Smoothsort]] if the priority queue is implemented with a Leonardo heap.
* [[Selection sort]] if the priority queue is implemented with an unordered array.
* [[Insertion sort]] if the priority queue is implemented with an ordered array.
* [[Tree sort]] if the priority queue is implemented with a [[self-balancing binary search tree]].
 
=== Using a sorting algorithm to make a priority queue ===
 
A sorting algorithm can also be used to implement a priority queue. Specifically, Thorup says:<ref>{{cite doi|10.1145/1314690.1314692}}</ref>
 
<blockquote>
We present a general deterministic linear space reduction from priority queues to sorting implying that if we can sort up to ''n'' keys in ''S''(''n'') time per key, then there is a priority queue supporting ''delete'' and ''insert'' in ''O''(''S''(''n'')) time and ''find-min'' in constant time.
</blockquote>
 
That is, if there is a sorting algorithm which can sort in ''O''(''S'') time per key, where ''S'' is some function of ''n'' and [[word size]],<ref>http://courses.csail.mit.edu/6.851/spring07/scribe/lec17.pdf</ref> then one can use the given procedure to create a priority queue where pulling the highest-priority element is ''O''(1) time, and inserting new elements (and deleting elements) is ''O''(''S'') time. For example, if one has an ''O''(''n''&nbsp;log&nbsp;log&nbsp;''n'') sort algorithm, one can create a priority queue with ''O''(1) pulling and ''O''(''n'' log&nbsp;log&nbsp;''n'') insertion.
 
== Libraries ==
 
A priority queue is often considered to be a "[[container (data structure)|container data structure]]".
 
The [[Standard Template Library]] (STL), and the [[C++]] 1998 standard, specifies <code>priority_queue</code> as one of the STL [[container (programming)|container]] [[adaptor (programming)|adaptor]] [[Template (programming)|class template]]s. It implements a max-priority-queue. Unlike actual STL containers, it does not allow [[Iterator|iteration]] of its elements (it strictly adheres to its abstract data type definition). STL also has utility functions for manipulating another random-access container as a binary max-heap. The [[Boost (C++ libraries)]] also have an implementation in the library heap.
 
Python's [http://docs.python.org/library/heapq.html heapq] module implements a binary min-heap on top of a list.
 
[[Java (programming language)|Java]]'s library contains a {{Javadoc:SE|java/util|PriorityQueue}} class, which implements a min-priority-queue.
 
[[Go (programming language)|Go]]'s library contains a [http://golang.org/pkg/container/heap/ container/heap] module, which implements a min-heap on top of any compatible data structure.
 
The [[Standard PHP Library]] extension contains the class [http://us2.php.net/manual/en/class.splpriorityqueue.php SplPriorityQueue].
 
Apple's [[Core Foundation]] framework contains a [http://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFBinaryHeapRef/Reference/reference.html CFBinaryHeap] structure, which implements a min-heap.
 
== Applications ==
 
=== Bandwidth management ===
 
Priority queuing can be used to manage limited resources such as [[Bandwidth (computing)|bandwidth]] on a transmission line from a [[computer network|network]] [[router (computing)|router]]. In the event of outgoing [[traffic]] queuing due to insufficient bandwidth, all other queues can be halted to send the traffic from the highest priority queue upon arrival. This ensures that the prioritized traffic (such as real-time traffic, e.g. an [[Real-time Transport Protocol|RTP]] stream of a [[Voice over Internet Protocol|VoIP]] connection) is forwarded with the least delay and the least likelihood of being rejected due to a queue reaching its maximum capacity. All other traffic can be handled when the highest priority queue is empty. Another approach used is to send disproportionately more traffic from higher priority queues.
 
Many modern protocols for [[Local Area Network]]s also include the concept of Priority Queues at the [[Media Access Control]] (MAC) sub-layer to ensure that high-priority applications (such as [[VoIP]] or [[IPTV]]) experience lower latency than other applications which can be served with [[Best effort]] service. Examples include [[IEEE 802.11e]] (an amendment to [[IEEE 802.11]] which provides [[Quality of Service]]) and [[ITU-T]] [[G.hn]] (a standard for high-speed [[Local area network]] using existing home wiring ([[Power line communication|power lines]], phone lines and [[Ethernet over coax|coaxial cables]]).
 
Usually a limitation (policer) is set to limit the bandwidth that traffic from the highest priority queue can take, in order to prevent high priority packets from choking off all other traffic. This limit is usually never reached due to high level control instances such as the [[Cisco Systems, Inc.|Cisco]] [[Callmanager]], which can be programmed to inhibit calls which would exceed the programmed bandwidth limit.
<!-- this was marked IMHO in the original
Priority queues exist on ISO-layer 2 (which is ethernet or WAN interfaces such as T1 / E1) and are filled by entry-criterions such as [[Diffserv]] Codepoints or IP-Precedence. Network equipment usually can be programmed to pick up prio packets by the layer 4 info (IP protocol and port) or the new one by a mechanism called [[NBAR]].
-->
 
=== Discrete event simulation ===
 
Another use of a priority queue is to manage the events in a [[discrete event simulation]]. The events are added to the queue with their simulation time used as the priority. The execution of the simulation proceeds by repeatedly pulling the top of the queue and executing the event thereon.
 
''See also'': [[Scheduling (computing)]], [[queueing theory]]
 
=== Dijkstra's algorithm ===
 
When the graph is stored in the form of adjacency list or matrix, priority queue can be used to extract minimum efficiently when implementing [[Dijkstra's algorithm]], although one also needs the ability to alter the priority of a particular vertex in the priority queue efficiently.
 
=== Huffman coding ===
 
[[Huffman coding]] requires one to repeatedly obtain the two lowest-frequency trees. A priority queue makes this efficient.
 
=== A* and SMA* search algorithms ===
 
The [[A* search algorithm]] finds the shortest path between two [[vertex (graph theory)|vertices]] or [[Node (graph theory)|nodes]] of a [[weighted graph]], trying out the most promising routes first. The priority queue (also known as the ''fringe'') is used to keep track of unexplored routes; the one for which a lower bound on the total path length is smallest is given highest priority. If memory limitations make [[A*]] impractical, the [[SMA*]] algorithm can be used instead, with a [[double-ended priority queue]] to allow removal of low-priority items.
 
=== ROAM triangulation algorithm ===
 
The Real-time Optimally Adapting Meshes ([[ROAM]]) algorithm computes a dynamically changing triangulation of a terrain. It works by splitting triangles where more detail is needed and merging them where less detail is needed. The algorithm assigns each triangle in the terrain a priority, usually related to the error decrease if that triangle would be split. The algorithm uses two priority queues, one for triangles that can be split and another for triangles that can be merged. In each step the triangle from the split queue with the highest priority is split, or the triangle from the merge queue with the lowest priority is merged with its neighbours.
 
== See also ==
 
* [[Batch queue]]
* [[Command queue]]
* [[Job scheduler]]
 
== References ==
 
{{Reflist}}
 
== Further reading ==
 
* [[Thomas H. Cormen]], [[Charles E. Leiserson]], [[Ronald L. Rivest]], and [[Clifford Stein]]. ''[[Introduction to Algorithms]]'', Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 6.5: Priority queues, pp.&nbsp;138&ndash;142.
 
== External links ==
 
* [http://en.cppreference.com/w/cpp/container/priority_queue C++ reference for <code>std::priority_queue</code>]
* [http://leekillough.com/heaps/ Descriptions] by [[Lee Killough (programmer)|Lee Killough]]
* [http://bitbucket.org/trijezdci/pqlib/src/ PQlib] - Open source Priority Queue library for C
* [http://github.com/vy/libpqueue libpqueue] is a generic priority queue (heap) implementation (in C) used by the Apache HTTP Server project.
* [http://www.theturingmachine.com/algorithms/heaps.html Survey of known priority queue structures] by Stefan Xenos
* [http://video.google.com/videoplay?docid=3499489585174920878 UC Berkeley - Computer Science 61B - Lecture 24: Priority Queues] (video) - introduction to priority queues using binary heap
 
{{Data structures}}
 
[[Category:Priority queues| ]]
[[Category:Abstract data types]]

Revision as of 20:32, 17 January 2014

Template:More footnotes In computer science/data structure, a priority queue is an abstract data type which is like a regular queue or stack data structure, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. If two elements have the same priority, they are served according to their order in the queue.

A priority queue is not a heap. A priority queue is an abstract concept like "a list" or "a map"; just as a list can be implemented with a linked list or an array, a priority queue can be implemented with a heap or a variety of other methods.

Operations

A priority queue must at least support the following operations:

  • insert_with_priority: add an element to the queue with an associated priority.
  • pull_highest_priority_element: remove the element from the queue that has the highest priority, and return it.
    This is also known as "pop_element(Off)", "get_maximum_element" or "get_front(most)_element".
    Some conventions reverse the order of priorities, considering lower values to be higher priority, so this may also be known as "get_minimum_element", and is often referred to as "get-min" in the literature.
    This may instead be specified as separate "peek_at_highest_priority_element" and "delete_element" functions, which can be combined to produce "pull_highest_priority_element".

In addition, peek (in this context often called find-max or find-min), which returns the highest-priority element but does not modify the queue, is very frequently implemented, and nearly always executes in O(1) time. This operation and its O(1) performance is crucial to many applications of priority queues.

More advanced implementations may support more complicated operations, such as pull_lowest_priority_element, inspecting the first few highest- or lowest-priority elements, clearing the queue, clearing subsets of the queue, performing a batch insert, merging two or more queues into one, incrementing priority of any element, etc.

Similarity to queues

One can imagine a priority queue as a modified queue, but when one would get the next element off the queue, the highest-priority element is retrieved first.

Stacks and queues may be modeled as particular kinds of priority queues. In a stack, the priority of each inserted element is monotonically increasing; thus, the last element inserted is always the first retrieved. In a queue, the priority of each inserted element is monotonically decreasing; thus, the first element inserted is always the first retrieved.

Implementation

Naive implementations

There are a variety of simple, usually inefficient, ways to implement a priority queue. They provide an analogy to help one understand what a priority queue is. For instance, one can keep all the elements in an unsorted list. Whenever the highest-priority element is requested, search through all elements for the one with the highest priority. (In big O notation: O(1) insertion time, O(n) pull time due to search.)

Usual implementation

To improve performance, priority queues typically use a heap as their backbone, giving O(log n) performance for inserts and removals, and O(n) to build initially. Alternatively, when a self-balancing binary search tree is used, insertion and removal also take O(log n) time, although building trees from existing sequences of elements takes O(n log n) time; this is typical where one might already have access to these data structures, such as with third-party or standard libraries.

Note that from a computational-complexity standpoint, priority queues are congruent to sorting algorithms. See the next section for how efficient sorting algorithms can create efficient priority queues.

There are several specialized heap data structures that either supply additional operations or outperform these approaches. The binary heap uses O(log n) time for both operations, but also allows queries of the element of highest priority without removing it in constant time. Binomial heaps add several more operations, but require O(log n) time for requests. Fibonacci heaps can insert elements, query the highest priority element, and increase an element's priority in amortized constant time,[1] though deletions are still O(log n). Brodal queues can do this in worst-case constant time.

While relying on a heap is a common way to implement priority queues, for integer data, faster implementations exist. This can even apply to data types that have a finite range, such as floats:

For applications that do many "peek" operations for every "extract-min" operation, the time complexity for peek actions can be reduced to O(1) in all tree and heap implementations by caching the highest priority element after every insertion and removal. For insertion, this adds at most a constant cost, since the newly inserted element is compared only to the previously cached minimum element. For deletion, this at most adds an additional "peek" cost, which is typically cheaper than the deletion cost, so overall time complexity is not significantly impacted.

Equivalence of priority queues and sorting algorithms

Using a priority queue to sort

The semantics of priority queues naturally suggest a sorting method: insert all the elements to be sorted into a priority queue, and sequentially remove them; they will come out in sorted order. This is actually the procedure used by several sorting algorithms, once the layer of abstraction provided by the priority queue is removed. This sorting method is equivalent to the following sorting algorithms:

Using a sorting algorithm to make a priority queue

A sorting algorithm can also be used to implement a priority queue. Specifically, Thorup says:[4]

We present a general deterministic linear space reduction from priority queues to sorting implying that if we can sort up to n keys in S(n) time per key, then there is a priority queue supporting delete and insert in O(S(n)) time and find-min in constant time.

That is, if there is a sorting algorithm which can sort in O(S) time per key, where S is some function of n and word size,[5] then one can use the given procedure to create a priority queue where pulling the highest-priority element is O(1) time, and inserting new elements (and deleting elements) is O(S) time. For example, if one has an O(n log log n) sort algorithm, one can create a priority queue with O(1) pulling and O(n log log n) insertion.

Libraries

A priority queue is often considered to be a "container data structure".

The Standard Template Library (STL), and the C++ 1998 standard, specifies priority_queue as one of the STL container adaptor class templates. It implements a max-priority-queue. Unlike actual STL containers, it does not allow iteration of its elements (it strictly adheres to its abstract data type definition). STL also has utility functions for manipulating another random-access container as a binary max-heap. The Boost (C++ libraries) also have an implementation in the library heap.

Python's heapq module implements a binary min-heap on top of a list.

Java's library contains a Template:Javadoc:SE class, which implements a min-priority-queue.

Go's library contains a container/heap module, which implements a min-heap on top of any compatible data structure.

The Standard PHP Library extension contains the class SplPriorityQueue.

Apple's Core Foundation framework contains a CFBinaryHeap structure, which implements a min-heap.

Applications

Bandwidth management

Priority queuing can be used to manage limited resources such as bandwidth on a transmission line from a network router. In the event of outgoing traffic queuing due to insufficient bandwidth, all other queues can be halted to send the traffic from the highest priority queue upon arrival. This ensures that the prioritized traffic (such as real-time traffic, e.g. an RTP stream of a VoIP connection) is forwarded with the least delay and the least likelihood of being rejected due to a queue reaching its maximum capacity. All other traffic can be handled when the highest priority queue is empty. Another approach used is to send disproportionately more traffic from higher priority queues.

Many modern protocols for Local Area Networks also include the concept of Priority Queues at the Media Access Control (MAC) sub-layer to ensure that high-priority applications (such as VoIP or IPTV) experience lower latency than other applications which can be served with Best effort service. Examples include IEEE 802.11e (an amendment to IEEE 802.11 which provides Quality of Service) and ITU-T G.hn (a standard for high-speed Local area network using existing home wiring (power lines, phone lines and coaxial cables).

Usually a limitation (policer) is set to limit the bandwidth that traffic from the highest priority queue can take, in order to prevent high priority packets from choking off all other traffic. This limit is usually never reached due to high level control instances such as the Cisco Callmanager, which can be programmed to inhibit calls which would exceed the programmed bandwidth limit.

Discrete event simulation

Another use of a priority queue is to manage the events in a discrete event simulation. The events are added to the queue with their simulation time used as the priority. The execution of the simulation proceeds by repeatedly pulling the top of the queue and executing the event thereon.

See also: Scheduling (computing), queueing theory

Dijkstra's algorithm

When the graph is stored in the form of adjacency list or matrix, priority queue can be used to extract minimum efficiently when implementing Dijkstra's algorithm, although one also needs the ability to alter the priority of a particular vertex in the priority queue efficiently.

Huffman coding

Huffman coding requires one to repeatedly obtain the two lowest-frequency trees. A priority queue makes this efficient.

A* and SMA* search algorithms

The A* search algorithm finds the shortest path between two vertices or nodes of a weighted graph, trying out the most promising routes first. The priority queue (also known as the fringe) is used to keep track of unexplored routes; the one for which a lower bound on the total path length is smallest is given highest priority. If memory limitations make A* impractical, the SMA* algorithm can be used instead, with a double-ended priority queue to allow removal of low-priority items.

ROAM triangulation algorithm

The Real-time Optimally Adapting Meshes (ROAM) algorithm computes a dynamically changing triangulation of a terrain. It works by splitting triangles where more detail is needed and merging them where less detail is needed. The algorithm assigns each triangle in the terrain a priority, usually related to the error decrease if that triangle would be split. The algorithm uses two priority queues, one for triangles that can be split and another for triangles that can be merged. In each step the triangle from the split queue with the highest priority is split, or the triangle from the merge queue with the lowest priority is merged with its neighbours.

See also

References

43 year old Petroleum Engineer Harry from Deep River, usually spends time with hobbies and interests like renting movies, property developers in singapore new condominium and vehicle racing. Constantly enjoys going to destinations like Camino Real de Tierra Adentro.

Further reading

External links

Template:Data structures

  1. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Chapter 20: Fibonacci Heaps, pp.476–497. Third edition p518.
  2. P. van Emde Boas. Preserving order in a forest in less than logarithmic time. In Proceedings of the 16th Annual Symposium on Foundations of Computer Science, pages 75-84. IEEE Computer Society, 1975.
  3. Michael L. Fredman and Dan E. Willard. Surpassing the information theoretic bound with fusion trees. Journal of Computer and System Sciences, 48(3):533-551, 1994
  4. Template:Cite doi
  5. http://courses.csail.mit.edu/6.851/spring07/scribe/lec17.pdf