1月7号什么星座| 胎儿右侧脉络丛囊肿是什么意思| 男人吃什么更持久| 建军节是什么时候| 大势至菩萨代表什么| 孩子铅高有什么症状| 口唇疱疹用什么药膏| cindy英文名什么意思| 姚字五行属什么| 献血前吃什么东西最好| 一到晚上就饿什么原因| pickup是什么意思| 屁多肚子胀是什么原因| 梦见别人买房子是什么预兆| 肺部硬结灶是什么意思| 脑梗吃什么药效果好| 析是什么意思| 香蕉有什么作用与功效| 狐臭和汗臭有什么区别| pr什么意思| 授受不亲什么意思| 梨状肌综合征挂什么科| 乳钉的作用是什么| 开水冲鸡蛋有什么好处| 义是什么意思| 吃什么能排出胆结石| 风湿性关节炎什么症状| editor是什么意思| c2m模式是什么意思| 眼睛流眼泪用什么眼药水| 夏末是什么时候| 吃虾不能吃什么| 塞翁失马是什么生肖| 粘胶是什么材质| 鱼漂什么牌子的好| 疖子是什么| 藿香正气水有什么作用| 孕早期失眠是什么原因| 糖尿病能吃什么主食| 胆囊炎有什么症状| 洗衣机不出水是什么原因| 咳嗽有绿痰是什么原因| lsa是什么意思| 穿青人是什么民族| c14呼气试验是检查什么的| 格桑是什么意思| 考试前紧张吃什么药最好能缓解| 立加羽念什么| 鸡子是什么东西| 支气管发炎用什么药| 系带断裂有什么影响吗| 思维什么意思| 投递是什么意思| 肌酐是什么病| 上海有什么烟| 梦见蛇和老鼠是什么意思| 牙结石不除有什么危害| 权志龙为什么这么火| 碘吃多了有什么危害| 2048年是什么年| copd是什么意思| 金骏眉属于什么茶类| 抽脂手术对身体有什么副作用| 椎间盘突出是什么意思| hi是什么意思| 肝弥漫性病变是什么意思| 金火什么字| 吃人嘴短拿人手软什么意思| 食物中毒吃什么| 男女授受不亲是什么意思| 军国主义是什么意思| 豆腐干炒什么菜好吃| 暂告一段落是什么意思| 风疹是什么样子图片| 做梦来月经了什么预兆| 腰疼肚子疼是什么原因引起的| 白天为什么能看到月亮| 湿气太重吃什么| 小孩口腔溃疡是什么原因引起的| 银属于五行属什么| 1998年什么命| 牛肉饺子馅配什么蔬菜好吃| 6岁属什么生肖| 游车河什么意思| 什么水果含糖量最低| 水果的英文是什么| 下体有异味是什么原因| 艾字五行属什么| 怀孕三个月吃什么对胎儿好| 梦见猫死了是什么意思| 吃b族维生素有什么好处| 钙化斑是什么意思| 叶赫那拉氏是什么旗| 什么的高楼| 血小板高是什么原因| 错构瘤是什么病| 睡觉起来头晕什么原因| 机械键盘什么轴最好| 酷暑难当是什么意思| 男性hpv挂什么科| 工程院院士是什么级别| 什么的雷雨| 工会主席是什么级别| 花痴是什么意思| 来例假腰疼是什么原因| 黄金变黑是什么原因| kcl是什么药| 经血粉红色是什么原因| nk是什么意思| 14年属什么| 向日葵代表什么意思| 饕餮长什么样| 车厘子和樱桃有什么区别| 荷塘月色是什么菜| 雌雄是什么意思| 今年28岁属什么| 崩漏下血是什么意思| 润滑油是什么| 眼拙是什么意思| 铁剂不能与什么同服| 什么是爱豆| 登高是什么意思| 藏红花是什么| 一月十九号是什么星座| 宝宝吃益生菌有什么好处和坏处| 孕期吃什么长胎不长肉| 六月六是什么节日| 神经性梅毒有什么症状| 学徒是什么意思| 胆固醇高会引起什么病| 先天愚型是什么病| 做梦梦到老公出轨代表什么预兆| 部首和偏旁有什么区别| 去年属什么生肖| 什么是肠痉挛| 两个o型血能生出什么血型的孩子| 脑软化灶是什么意思| 套马的汉子你威武雄壮是什么歌| 脖子粗挂什么科| 脑血管造影是什么意思| 家里养什么鱼好| 生理盐水和食用盐水有什么区别| 显妣是什么意思| 胃胀嗳气吃什么药最有效| 血糖高适合喝什么牛奶| 不骄不躁是什么意思| 葡萄糖偏低是什么意思| 吃什么能治结石| 类风湿有什么症状| 白兰地是什么酒| 午时是什么时间| 秃顶是什么原因造成的| 肛门潮湿瘙痒用什么药最好| 伤口愈合为什么会痒| 四书五经是什么| 外甥女是什么关系| 尿发黄是什么原因| 上感是什么意思| 扁桃体炎吃什么消炎药| 澳门是什么时候回归的| 长春有什么大学| 久站腿肿是什么原因引起的| 拉肚子吃什么消炎药好| 什么样的女孩容易招鬼| 空调制热效果不好什么原因| 凝固酶阳性是什么意思| 梦见看电影是什么意思| 喝什么减肥| 普萘洛尔是什么药| 吃什么清肺养肺| 哈喇味是什么味道| 张艺谋为什么不娶巩俐| 肺炎是什么| 男人前列腺在什么位置| 距骨在什么位置| 相亲为什么不能拖太久| 猪肝配什么菜炒好吃| 皮肤黑是什么原因| 比重是什么| 结余是什么意思| 屁股长痘是什么原因| 肚子突然疼是什么原因| 88属什么| 日本旅游买什么东西最划算| 过敏性鼻炎吃什么药能快速缓解| 医学pr是什么意思| 嗳是什么意思| 困惑是什么意思| 美是什么生肖| 五行属什么怎么看| 大脚趾外翻是什么原因| n字鞋子是什么牌子| 喉结是什么| 继发性闭经是什么意思| 阿修罗道是什么意思| 左上腹是什么器官| 尿酸盐结晶是什么意思| 益生菌有什么功效| 吃什么降羊水最快| 护理专业是做什么的| 本来无一物何处惹尘埃什么意思| 哈怂是什么意思| adr是什么激素| 新生儿五行缺什么查询| 什么是动车| 五浊恶世是什么意思| 皮肤过敏用什么药最好| 力所能及什么意思| 宝宝拉水便是什么原因| 落英缤纷是什么意思| 供给侧改革什么意思| 什么是正装| 输钾为什么会痛| 名节是什么意思| 左心室高电压是什么意思| 马克笔是什么笔| 生物制剂是什么药| 男性hpv检查挂什么科| 为什么拉绿色的屎| 正财代表什么| eap是什么| 鸡飞狗跳的意思是什么| 头孢喝酒有什么反应| 脚癣是什么原因引起的| 猫咪结膜炎用什么药好| 紧急避孕药有什么副作用| 痛风反复发作什么原因| 八月八日是什么星座| 浑身没劲是什么原因| 压箱钱是什么意思| 打封闭针是什么意思| 三角梅什么时候开花| 脓疱疮是什么原因引起的| 什么的歌声填词语| 什么的眼睛填空| 花瓣是什么意思| daddy什么意思| 多维元素片有什么作用| 乙状结肠炎吃什么药| 白癜风早期症状是什么| 白球比偏低吃什么补| 物极必反什么意思| 牛剖层皮革是什么意思| 全血细胞减少是什么意思| 男人喝什么酒壮阳最快| 喝什么粥降血糖| 死缓什么意思| lo是什么意思| 湿气重是什么意思| 尿痛流脓吃什么药| 毛爷爷是什么意思| 窝在沙发里是什么歌| 射手座和什么座最配对| 祀是什么意思| 国家三有保护动物是什么意思| 三项规定内容是什么| 洋葱什么时候种植| 凉拌什么菜好吃| 楠字取名有什么寓意| 人大副主任是什么级别| 什么饼不能吃脑筋急转弯| 门当是什么| 宜入宅是什么意思| bi是什么意思| 百度Jump to content

中国游客在泰遇车祸4人伤势较重 文化和旅游部关注

From Wikipedia, the free encyclopedia
百度 常吃甜食,视力智商差北京协和医院内分泌科教授潘慧你是否经常拿糖果奖励孩子孩子是否每天用甜饮料代替白开水解渴糖虽然是生长发育必不可少的能量来源,但长期大量吃糖严重威胁健康。

In computer science, a priority queue is an abstract data type similar to a regular queue or stack abstract data type.

In a priority queue, each element has an associated priority, which determines its order of service.[1] Priority queue serves highest priority items first.[1] Priority values have to be instances of an ordered data type, and higher priority can be given either to the lesser or to the greater values with respect to the given order relation. For example, in Java standard library, PriorityQueue's the least elements with respect to the order have the highest priority.[2] This implementation detail is without much practical significance, since passing to the opposite order relation turns the least values into the greatest, and vice versa.

While priority queues are often implemented using heaps, they are conceptually distinct. A priority queue can be implemented with a heap or with other methods; just as a list can be implemented with a linked list or with an array.

Operations

[edit]

A priority queue has the following operations:[3][4][5]

Max-priority queue

[edit]
  • insert(S, element, priority):[4][5] add an element to set S with an associated priority.
  • maximum(S): return the element with highest priority.
    This is also known as "find_max".
  • extract_max(S): remove the element from set S with highest priority, and return it.
    This is also known as "delete",[4] or "extract".[5]
  • increase_key(S, element, k): increase the associated priority with an element to the new value k.

Min-priority queue

[edit]
  • insert(S, element, priority):[4][5] add an element to set S with an associated priority.
  • minimum(S): return the element with lowest priority.
    This is also known as "find_min".
  • extract_min(S): remove the element from set S with lowest priority, and return it.
    This is also known as "delete",[4] or "extract".[5]
  • decrease_key(S, element, k): decrease the associated priority with an element to the new value k.

Stacks and queues can be implemented as particular kinds of priority queues, with the priority determined by the order in which the elements are inserted. 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.

In some implementations, if two elements have the same priority, they are served in the same order in which they were enqueued. In other implementations, the order of elements with the same priority is undefined.

Implementation

[edit]

Naive implementations

[edit]

One can create a simple, but inefficient priority queue in a number of ways. These naive implementations can demonstrate the expected behaviour of a priority queue in a simpler manner.

  • insert elements into an unsorted array; find and extract element with highest priority
    Performance: "insert" performs in O(1) constant time, where "extract_max" performs in O(n) linear time.
insert(element, priority):
    node.element ← element
    node.priority ← priority
    list.append(node)

extract_max():
    highest ← 0
    foreach node in list:
        if highest.priority < node.priority:
            highest ← node
    list.remove(highest)
    return highest.element
  • insert elements into a sorted array; extract first element
    Performance: "insert" performs in O(n) linear time, where "extract_max" performs in O(1) constant time.
insert(element, priority):
    node.element ← element
    node.priority ← priority
    for i in [0...N]:
        element ← list.get_at_index(i)
        if element.priority < node.priority:
            list.insert_at_index(node, i + 1)
            return

extract_max():
    highest ← list.get_at_index(0)
    list.remove(highest)
    return highest.element

Usual implementation

[edit]

To improve performance, priority queues are typically based on a heap, giving O(log n) performance for inserts and removals, and O(n) to build the heap initially from a set of n elements. Variants of the basic heap data structure such as pairing heaps or Fibonacci heaps can provide better bounds for some operations.[6]

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. From a space-complexity standpoint, using self-balancing binary search tree with linked list takes more storage, since it requires to store extra references to other nodes.

From a computational-complexity standpoint, priority queues are congruent to sorting algorithms. The section on the equivalence of priority queues and sorting algorithms, below, describes how efficient sorting algorithms can create efficient priority queues.

Specialized heaps

[edit]

There are several specialized heap data structures that either supply additional operations or outperform heap-based implementations for specific types of keys, specifically integer keys. Suppose the set of possible keys is {1, 2, ..., C}.

  • When only insert, find-min and extract-min are needed and in case of integer priorities, a bucket queue can be constructed as an array of C linked lists plus a pointer top, initially C. Inserting an item with key k appends the item to the k'th list, and updates top ← min(top, k), both in constant time. Extract-min deletes and returns one item from the list with index top, then increments top if needed until it again points to a non-empty list; this takes O(C) time in the worst case. These queues are useful for sorting the vertices of a graph by their degree.[7]: 374 
  • A van Emde Boas tree supports the minimum, maximum, insert, delete, search, extract-min, extract-max, predecessor and successor] operations in O(log log C) time, but has a space cost for small queues of about O(2m/2), where m is the number of bits in the priority value.[8] The space can be reduced significantly with hashing.
  • The Fusion tree by Fredman and Willard implements the minimum operation in O(1) time and insert and extract-min operations in time. However it is stated by the author that, "Our algorithms have theoretical interest only; The constant factors involved in the execution times preclude practicality."[9]

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.

Monotone priority queues are specialized queues that are optimized for the case where no item is ever inserted that has a lower priority (in the case of min-heap) than any item previously extracted. This restriction is met by several practical applications of priority queues.

Summary of running times

[edit]

Here are time complexities[10] of various heap data structures. The abbreviation am. indicates that the given complexity is amortized, otherwise it is a worst-case complexity. For the meaning of "O(f)" and "Θ(f)" see Big O notation. Names of operations assume a min-heap.

Operation find-min delete-min decrease-key insert meld make-heap[a]
Binary[10] Θ(1) Θ(log n) Θ(log n) Θ(log n) Θ(n) Θ(n)
Skew[11] Θ(1) O(log n) am. O(log n) am. O(log n) am. O(log n) am. Θ(n) am.
Leftist[12] Θ(1) Θ(log n) Θ(log n) Θ(log n) Θ(log n) Θ(n)
Binomial[10][14] Θ(1) Θ(log n) Θ(log n) Θ(1) am. Θ(log n)[b] Θ(n)
Skew binomial[15] Θ(1) Θ(log n) Θ(log n) Θ(1) Θ(log n)[b] Θ(n)
2–3 heap[17] Θ(1) O(log n) am. Θ(1) Θ(1) am. O(log n)[b] Θ(n)
Bottom-up skew[11] Θ(1) O(log n) am. O(log n) am. Θ(1) am. Θ(1) am. Θ(n) am.
Pairing[18] Θ(1) O(log n) am. o(log n) am.[c] Θ(1) Θ(1) Θ(n)
Rank-pairing[21] Θ(1) O(log n) am. Θ(1) am. Θ(1) Θ(1) Θ(n)
Fibonacci[10][22] Θ(1) O(log n) am. Θ(1) am. Θ(1) Θ(1) Θ(n)
Strict Fibonacci[23][d] Θ(1) Θ(log n) Θ(1) Θ(1) Θ(1) Θ(n)
Brodal[24][d] Θ(1) Θ(log n) Θ(1) Θ(1) Θ(1) Θ(n)[25]
  1. ^ make-heap is the operation of building a heap from a sequence of n unsorted elements. It can be done in Θ(n) time whenever meld runs in O(log n) time (where both complexities can be amortized).[11][12] Another algorithm achieves Θ(n) for binary heaps.[13]
  2. ^ a b c For persistent heaps (not supporting decrease-key), a generic transformation reduces the cost of meld to that of insert, while the new cost of delete-min is the sum of the old costs of delete-min and meld.[16] Here, it makes meld run in Θ(1) time (amortized, if the cost of insert is) while delete-min still runs in O(log n). Applied to skew binomial heaps, it yields Brodal-Okasaki queues, persistent heaps with optimal worst-case complexities.[15]
  3. ^ Lower bound of [19] upper bound of [20]
  4. ^ a b Brodal queues and strict Fibonacci heaps achieve optimal worst-case complexities for heaps. They were first described as imperative data structures. The Brodal-Okasaki queue is a persistent data structure achieving the same optimum, except that decrease-key is not supported.

Equivalence of priority queues and sorting algorithms

[edit]

Using a priority queue to sort

[edit]

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:

Name Priority Queue Implementation Best Average Worst
Heapsort Heap n log n n log n n log n
Smoothsort Leonardo Heap n n log n n log n
Selection sort Unordered Array n2 n2 n2
Insertion sort Ordered Array n n2 n2
Tree sort Self-balancing binary search tree n log n n log n n log n

Using a sorting algorithm to make a priority queue

[edit]

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

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,[27] 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 n) sort algorithm, one can create a priority queue with O(1) pulling and O( log n) insertion.

Libraries

[edit]

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

The Standard Template Library (STL), and the C++ 1998 standard, specifies std::priority_queue as one of the STL container adaptor class templates. However, it does not specify how two elements with same priority should be served, and indeed, common implementations will not return them according to their order in the queue. It implements a max-priority-queue, and has three parameters: a comparison object for sorting such as a function object (defaults to less<T> if unspecified), the underlying container for storing the data structures (defaults to std::vector<T>), and two iterators to the beginning and end of a sequence. 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 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 PriorityQueue class, which implements a min-priority-queue as a binary heap.

.NET's library contains a PriorityQueue class, which implements an array-backed, quaternary min-heap.

Scala's library contains a PriorityQueue class, which implements a max-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

[edit]

Bandwidth management

[edit]

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

[edit]

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

[edit]

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.

If instead, a graph is stored as node objects, and priority-node pairs are inserted into a heap, altering the priority of a particular vertex is not necessary if one tracks visited nodes. Once a node is visited, if it comes up in the heap again (having had a lower priority number associated with it earlier), it is popped-off and ignored.

Huffman coding

[edit]

Huffman coding requires one to repeatedly obtain the two lowest-frequency trees. A priority queue is one method of doing this.

Best-first search algorithms

[edit]

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

ROAM triangulation algorithm

[edit]

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.

Prim's algorithm for minimum spanning tree

[edit]

Using min heap priority queue in Prim's algorithm to find the minimum spanning tree of a connected and undirected graph, one can achieve a good running time. This min heap priority queue uses the min heap data structure which supports operations such as insert, minimum, extract-min, decrease-key.[28] In this implementation, the weight of the edges is used to decide the priority of the vertices. Lower the weight, higher the priority and higher the weight, lower the priority.[29]

Parallel priority queue

[edit]

Parallelization can be used to speed up priority queues, but requires some changes to the priority queue interface. The reason for such changes is that a sequential update usually only has or cost, and there is no practical gain to parallelize such an operation. One possible change is to allow the concurrent access of multiple processors to the same priority queue. The second possible change is to allow batch operations that work on elements, instead of just one element. For example, extractMin will remove the first elements with the highest priority.

Concurrent parallel access

[edit]

If the priority queue allows concurrent access, multiple processes can perform operations concurrently on that priority queue. However, this raises two issues. First of all, the definition of the semantics of the individual operations is no longer obvious. For example, if two processes want to extract the element with the highest priority, should they get the same element or different ones? This restricts parallelism on the level of the program using the priority queue. In addition, because multiple processes have access to the same element, this leads to contention.

Node 3 is inserted and sets the pointer of node 2 to node 3. Immediately after that, node 2 is deleted and the pointer of node 1 is set to node 4. Now node 3 is no longer reachable.

The concurrent access to a priority queue can be implemented on a Concurrent Read, Concurrent Write (CRCW) PRAM model. In the following the priority queue is implemented as a skip list.[30][31] In addition, an atomic synchronization primitive, CAS, is used to make the skip list lock-free. The nodes of the skip list consists of a unique key, a priority, an array of pointers, for each level, to the next nodes and a delete mark. The delete mark marks if the node is about to be deleted by a process. This ensures that other processes can react to the deletion appropriately.

  • insert(e): First, a new node with a key and a priority is created. In addition, the node is assigned a number of levels, which dictates the size of the array of pointers. Then a search is performed to find the correct position where to insert the new node. The search starts from the first node and from the highest level. Then the skip list is traversed down to the lowest level until the correct position is found. During the search, for every level the last traversed node will be saved as parent node for the new node at that level. In addition, the node to which the pointer, at that level, of the parent node points towards, will be saved as the successor node of the new node at that level. Afterwards, for every level of the new node, the pointers of the parent node will be set to the new node. Finally, the pointers, for every level, of the new node will be set to the corresponding successor nodes.
  • extract-min: First, the skip list is traversed until a node is reached whose delete mark is not set. This delete mark is than set to true for that node. Finally the pointers of the parent nodes of the deleted node are updated.

If the concurrent access to a priority queue is allowed, conflicts may arise between two processes. For example, a conflict arises if one process is trying to insert a new node, but at the same time another process is about to delete the predecessor of that node.[30] There is a risk that the new node is added to the skip list, yet it is not longer reachable. (See image)

K-element operations

[edit]

In this setting, operations on a priority queue is generalized to a batch of elements. For instance, k_extract-min deletes the smallest elements of the priority queue and returns those.

In a shared-memory setting, the parallel priority queue can be easily implemented using parallel binary search trees and join-based tree algorithms. In particular, k_extract-min corresponds to a split on the binary search tree that has cost and yields a tree that contains the smallest elements. k_insert can be applied by a union of the original priority queue and the batch of insertions. If the batch is already sorted by the key, k_insert has cost. Otherwise, we need to first sort the batch, so the cost will be . Other operations for priority queue can be applied similarly. For instance, k_decrease-key can be done by first applying difference and then union, which first deletes the elements and then inserts them back with the updated keys. All these operations are highly parallel, and the theoretical and practical efficiency can be found in related research papers.[32][33]

The rest of this section discusses a queue-based algorithm on distributed memory. We assume each processor has its own local memory and a local (sequential) priority queue. The elements of the global (parallel) priority queue are distributed across all processors.

k_extract-min is executed on a priority queue with three processors. The green elements are returned and removed from the priority queue.

A k_insert operation assigns the elements uniformly random to the processors which insert the elements into their local queues. Note that single elements can still be inserted into the queue. Using this strategy the global smallest elements are in the union of the local smallest elements of every processor with high probability. Thus each processor holds a representative part of the global priority queue.

This property is used when k_extract-min is executed, as the smallest elements of each local queue are removed and collected in a result set. The elements in the result set are still associated with their original processor. The number of elements that is removed from each local queue depends on and the number of processors . [34] By parallel selection the smallest elements of the result set are determined. With high probability these are the global smallest elements. If not, elements are again removed from each local queue and put into the result set. This is done until the global smallest elements are in the result set. Now these elements can be returned. All other elements of the result set are inserted back into their local queues. The running time of k_extract-min is expected , where and is the size of the priority queue.[34]

The priority queue can be further improved by not moving the remaining elements of the result set directly back into the local queues after a k_extract-min operation. This saves moving elements back and forth all the time between the result set and the local queues.

By removing several elements at once a considerable speedup can be reached. But not all algorithms can use this kind of priority queue. Dijkstra's algorithm for example can not work on several nodes at once. The algorithm takes the node with the smallest distance from the priority queue and calculates new distances for all its neighbor nodes. If you would take out nodes, working at one node could change the distance of another one of the nodes. So using k-element operations destroys the label setting property of Dijkstra's algorithm.

See also

[edit]

References

[edit]
  1. ^ a b Miller Jr., Robert G. (1960). "Priority queues" (PDF). The Annals of Mathematical Statistics. 31. Stanford University: 86–103. doi:10.1214/aoms/1177705990.
  2. ^ "PriorityQueue (Java SE 9 & JDK 9 )". docs.oracle.com. Retrieved 2025-08-14.
  3. ^ Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2022) [1990]. "Chapter 6.5: Priority queues". Introduction to Algorithms (4th ed.). MIT Press and McGraw-Hill. pp. 172–176. ISBN 0-262-04630-X.
  4. ^ a b c d e R?nngren, Robert; Ayani, Rassul (2025-08-14). "A comparative study of parallel and sequential priority queue algorithms". ACM Trans. Model. Comput. Simul. 7 (2): 157–209. doi:10.1145/249204.249205. ISSN 1049-3301.
  5. ^ a b c d e Ayani, R. (December 1990). "LR-algorithm: Concurrent operations on priority queues". Proceedings of the Second IEEE Symposium on Parallel and Distributed Processing 1990. pp. 22–25. doi:10.1109/SPDP.1990.143500. ISBN 0-8186-2087-0.
  6. ^ Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2001) [1990]. "Chapter 20: Fibonacci Heaps". Introduction to Algorithms (2nd ed.). MIT Press and McGraw-Hill. pp. 476–497. ISBN 0-262-03293-7. Third edition, p. 518.
  7. ^ Skiena, Steven (2010). The Algorithm Design Manual (2nd ed.). Springer Science+Business Media. ISBN 978-1-849-96720-4.
  8. ^ 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.
  9. ^ 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
  10. ^ a b c d Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L. (1990). Introduction to Algorithms (1st ed.). MIT Press and McGraw-Hill. ISBN 0-262-03141-8.
  11. ^ a b c Sleator, Daniel Dominic; Tarjan, Robert Endre (February 1986). "Self-Adjusting Heaps". SIAM Journal on Computing. 15 (1): 52–69. CiteSeerX 10.1.1.93.6678. doi:10.1137/0215004. ISSN 0097-5397.
  12. ^ a b Tarjan, Robert (1983). "3.3. Leftist heaps". Data Structures and Network Algorithms. pp. 38–42. doi:10.1137/1.9781611970265. ISBN 978-0-89871-187-5.
  13. ^ Hayward, Ryan; McDiarmid, Colin (1991). "Average Case Analysis of Heap Building by Repeated Insertion" (PDF). J. Algorithms. 12: 126–153. CiteSeerX 10.1.1.353.7888. doi:10.1016/0196-6774(91)90027-v. Archived from the original (PDF) on 2025-08-14. Retrieved 2025-08-14.
  14. ^ "Binomial Heap | Brilliant Math & Science Wiki". brilliant.org. Retrieved 2025-08-14.
  15. ^ a b Brodal, Gerth St?lting; Okasaki, Chris (November 1996), "Optimal purely functional priority queues", Journal of Functional Programming, 6 (6): 839–857, doi:10.1017/s095679680000201x
  16. ^ Okasaki, Chris (1998). "10.2. Structural Abstraction". Purely Functional Data Structures (1st ed.). pp. 158–162. ISBN 9780521631242.
  17. ^ Takaoka, Tadao (1999), Theory of 2–3 Heaps (PDF), p. 12
  18. ^ Iacono, John (2000), "Improved upper bounds for pairing heaps", Proc. 7th Scandinavian Workshop on Algorithm Theory (PDF), Lecture Notes in Computer Science, vol. 1851, Springer-Verlag, pp. 63–77, arXiv:1110.4428, CiteSeerX 10.1.1.748.7812, doi:10.1007/3-540-44985-X_5, ISBN 3-540-67690-2
  19. ^ Fredman, Michael Lawrence (July 1999). "On the Efficiency of Pairing Heaps and Related Data Structures" (PDF). Journal of the Association for Computing Machinery. 46 (4): 473–501. doi:10.1145/320211.320214.
  20. ^ Pettie, Seth (2005). Towards a Final Analysis of Pairing Heaps (PDF). FOCS '05 Proceedings of the 46th Annual IEEE Symposium on Foundations of Computer Science. pp. 174–183. CiteSeerX 10.1.1.549.471. doi:10.1109/SFCS.2005.75. ISBN 0-7695-2468-0.
  21. ^ Haeupler, Bernhard; Sen, Siddhartha; Tarjan, Robert E. (November 2011). "Rank-pairing heaps" (PDF). SIAM J. Computing. 40 (6): 1463–1485. doi:10.1137/100785351.
  22. ^ Fredman, Michael Lawrence; Tarjan, Robert E. (July 1987). "Fibonacci heaps and their uses in improved network optimization algorithms" (PDF). Journal of the Association for Computing Machinery. 34 (3): 596–615. CiteSeerX 10.1.1.309.8927. doi:10.1145/28869.28874.
  23. ^ Brodal, Gerth St?lting; Lagogiannis, George; Tarjan, Robert E. (2012). Strict Fibonacci heaps (PDF). Proceedings of the 44th symposium on Theory of Computing - STOC '12. pp. 1177–1184. CiteSeerX 10.1.1.233.1740. doi:10.1145/2213977.2214082. ISBN 978-1-4503-1245-5.
  24. ^ Brodal, Gerth S. (1996), "Worst-Case Efficient Priority Queues" (PDF), Proc. 7th Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 52–58
  25. ^ Goodrich, Michael T.; Tamassia, Roberto (2004). "7.3.6. Bottom-Up Heap Construction". Data Structures and Algorithms in Java (3rd ed.). pp. 338–341. ISBN 0-471-46983-1.
  26. ^ Thorup, Mikkel (2007). "Equivalence between priority queues and sorting". Journal of the ACM. 54 (6): 28. doi:10.1145/1314690.1314692. S2CID 11494634.
  27. ^ "Archived copy" (PDF). Archived (PDF) from the original on 2025-08-14. Retrieved 2025-08-14.{{cite web}}: CS1 maint: archived copy as title (link)
  28. ^ Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2009) [1990]. Introduction to Algorithms (3rd ed.). MIT Press and McGraw-Hill. p. 634. ISBN 0-262-03384-4. "In order to implement Prim's algorithm efficiently, we need a fast way to select a new edge to add to the tree formed by the edges in A."
  29. ^ "Prim's Algorithm". Geek for Geeks. 18 November 2012. Archived from the original on 9 September 2014. Retrieved 12 September 2014.
  30. ^ a b Sundell, H?kan; Tsigas, Philippas (2005). "Fast and lock-free concurrent priority queues for multi-thread systems". Journal of Parallel and Distributed Computing. 65 (5): 609–627. CiteSeerX 10.1.1.67.1310. doi:10.1109/IPDPS.2003.1213189. S2CID 20995116.
  31. ^ Lindén, Jonsson (2013), "A Skiplist-Based Concurrent Priority Queue with Minimal Memory Contention", Technical Report 2018-003 (in German)
  32. ^ Blelloch, Guy E.; Ferizovic, Daniel; Sun, Yihan (2016), "Just Join for Parallel Ordered Sets", Symposium on Parallel Algorithms and Architectures, Proc. of 28th ACM Symp. Parallel Algorithms and Architectures (SPAA 2016), ACM, pp. 253–264, arXiv:1602.02120, doi:10.1145/2935764.2935768, ISBN 978-1-4503-4210-0, S2CID 2897793
  33. ^ Blelloch, Guy E.; Ferizovic, Daniel; Sun, Yihan (2018), "PAM: parallel augmented maps", Proceedings of the 23rd ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, ACM, pp. 290–304
  34. ^ a b Sanders, Peter; Mehlhorn, Kurt; Dietzfelbinger, Martin; Dementiev, Roman (2019). Sequential and Parallel Algorithms and Data Structures - The Basic Toolbox. Springer International Publishing. pp. 226–229. doi:10.1007/978-3-030-25209-0. ISBN 978-3-030-25208-3. S2CID 201692657.

Further reading

[edit]
[edit]
肌张力是什么意思 水痘疫苗什么时候打 为什么会得霉菌性阴道炎 什么叫幸福 忉利天是什么意思
玙字五行属什么 天天喝可乐有什么危害 小儿割包皮挂什么科 藜芦是什么东西 喝酒前喝什么不容易醉
痰多咳嗽是什么原因 尿素高不能吃什么 便秘吃什么药好 工薪阶层是什么意思 高光是什么意思
国债什么意思 属狗的什么命 气阴两虚是什么意思 c肽是什么 奶霜是什么
今年是什么命hcv8jop7ns1r.cn 足下生辉是什么意思hcv7jop5ns0r.cn 士官是什么hcv9jop7ns0r.cn mt什么意思creativexi.com 一竖一点念什么hcv8jop9ns8r.cn
00年属龙的是什么命hcv8jop0ns5r.cn 为什么叫211大学cj623037.com 一个口一个犬读什么hcv8jop7ns2r.cn 坐车晕车是什么原因hcv8jop7ns2r.cn 什么猫掉毛少hcv8jop3ns0r.cn
旻字五行属什么hcv8jop5ns1r.cn 上课什么坐姿可以瘦腿hcv9jop6ns6r.cn 一什么杨桃zsyouku.com 莽是什么意思hcv8jop2ns5r.cn 代谢不好吃什么药hcv7jop9ns6r.cn
拔罐对身体有什么好处和坏处hcv9jop6ns3r.cn 音欠读什么hcv8jop2ns5r.cn 后羿射日什么意思hcv8jop0ns5r.cn 小伙子是什么意思hcv9jop4ns0r.cn 虚火是什么意思hcv8jop9ns4r.cn
百度