An experimental study of priority queues By Claus Jensen University of Copenhagen.

Slides:



Advertisements
Similar presentations
§6 Leftist Heaps CHAPTER 5 Graph Algorithms  Heap: Structure Property + Order Property Target : Speed up merging in O(N). Leftist Heap: Order Property.
Advertisements

Binary Trees CS 110: Data Structures and Algorithms First Semester,
1 HeapSort CS 3358 Data Structures. 2 Heapsort: Basic Idea Problem: Arrange an array of items into sorted order. 1) Transform the array of items into.
CS 315 March 24 Goals: Heap (Chapter 6) priority queue definition of a heap Algorithms for Insert DeleteMin percolate-down Build-heap.
A Binary Tree root leaf. A Binary Tree root leaf descendent of root parent of leaf.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Nick Harvey & Kevin Zatloukal
Initializing A Max Heap input array = [-, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
PQ, binary heaps G.Kamberova, Algorithms Priority Queue ADT Binary Heaps Gerda Kamberova Department of Computer Science Hofstra University.
Heaps and heapsort COMP171 Fall 2005 Part 2. Sorting III / Slide 2 Heap: array implementation Is it a good idea to store arbitrary.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 20: Binary Trees.
Priority Queues, Heaps & Leftist Trees
Binary Trees Chapter 6.
1 Priority Queues (Heaps)  Sections 6.1 to The Priority Queue ADT  DeleteMin –log N time  Insert –log N time  Other operations –FindMin  Constant.
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
CHAPTER 71 TREE. Binary Tree A binary tree T is a finite set of one or more nodes such that: (a) T is empty or (b) There is a specially designated node.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Tree.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
Data Structure & Algorithm II.  Delete-min  Building a heap in O(n) time  Heap Sort.
Chapter 21 Binary Heap.
data ordered along paths from root to leaf
Chapter 11 Heap. Overview ● The heap is a special type of binary tree. ● It may be used either as a priority queue or as a tool for sorting.
„Policy-Based Benchmarking of Weak Heaps and Their Relatives“ Asger Bruun*, Stefan Edelkamp, Jyrki Katajainen*, Jens Rasmussen* *University of Copenhagen.
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Two-tier relaxed heaps Presented by Claus Jensen Joint work with Amr Elmasry and Jyrki Katajainen Slides available at
FALL 2005CENG 213 Data Structures1 Priority Queues (Heaps) Reference: Chapter 7.
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Heaps © 2010 Goodrich, Tamassia. Heaps2 Priority Queue ADT  A priority queue (PQ) stores a collection of entries  Typically, an entry is a.
Trees CSIT 402 Data Structures II 1. 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical.
Navigation Piles with Applications to Sorting, Priority Queues, and Priority Deques Jyrki Katajainen and Fabio Vitale Department of Computing, University.
1 Priority Queues (Heaps). 2 Priority Queues Many applications require that we process records with keys in order, but not necessarily in full sorted.
Heaps and Priority Queues What is a heap? A heap is a binary tree storing keys at its internal nodes and satisfying the following properties:
CSE 373 Data Structures Lecture 7
Sorting With Priority Queue In-place Extra O(N) space
Chapter 12 – Data Structures
CC 215 Data Structures Trees
Red Black Trees Colored Nodes Definition Binary search tree.
Experimental evaluation of Navigation piles
AVL Tree.
Hashing Exercises.
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
CSE 373 Data Structures Lecture 7
CMSC 341 Lecture 13 Leftist Heaps
Priority Queues Sections 6.1 to 6.5.
Tree data structure.
Interval Heaps Complete binary tree.
More on Merge Sort CS 244 This presentation is not given in class
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
Trees and Binary Trees.
Trees 1: Theory, Models, Generic Heap Algorithms, Priority Queues
Priority Queues and Heaps
Initializing A Max Heap
Heapsort Heap & Priority Queue.
Tree data structure.
Data Structures and Algorithms
Balanced-Trees This presentation shows you the potential problem of unbalanced tree and show two way to fix it This lecture introduces heaps, which are.
Trees CSE 373 Data Structures.
Heaps and the Heapsort Heaps and priority queues
Tree Representation Heap.
Ch. 8 Priority Queues And Heaps
Balanced-Trees This presentation shows you the potential problem of unbalanced tree and show two way to fix it This lecture introduces heaps, which are.
CMSC 202 Trees.
CSE 373, Copyright S. Tanimoto, 2002 Priority Queues -
CS 6310 Advanced Data Structure Wei-Shian Wang
Trees CSE 373 Data Structures.
Trees CSE 373 Data Structures.
A Heap Is Efficiently Represented As An Array
EE 312 Software Design and Implementation I
Presentation transcript:

An experimental study of priority queues By Claus Jensen University of Copenhagen

STL The STL impose the following requirement on the algorithms: Top O(1) Pop 2log(n) Push log(n) Make 3n Where n is the number of elements in the priority queue.

The Algorithms benchmarked Implicit binary heap Navigation piles Weight-biased leftist trees

Implicit binary heap Space requirements No extra space needed. Requirement on the number of Element comparisons. Top O(1) Pop 2 log n Push log n

Navigation piles Introduced by Jyrki Katajainen and Fabio Vitale.

Structure of navigation piles Shape  It is a left-complete binary tree of size N, where N ≥ n (# of elements stored). Leaf  The leaves are used to store the elements.  The first n leaves store one element each, the rest are empty.

Structure of navigation piles Branch:  A branch (node) contains the index of the leaf storing the top element among the group of elements attached to the leaves in the subtree rooted by the branch.

Structure of navigation piles Representation:  The elements are stored in sequence A[0..n).  The branches are stored in sequence B[0..N).

Structure of navigation piles

Functions Make  Construction of a navigation pile is done by visiting the branches in a bottom-up manner and computing its index using the indices available at the children. n-1 element comparisons n element moves O(n) instructions

Functions Push  A new element is inserted into the first empty leaf, followed by an update of the branches from the leaf to the root. A binary search strategy can be used in the update. loglog n + O(1) element comparisons 1 element move O(log n) instructions

Functions Top  A reference to the top element stored at the root is returned. O(1) instructions

Functions Pop  The top element is erased and the indices are updated.  The update is done in three different ways depending on circumstances inside the navigation pile. Ceiling of log n element comparisons 1 or 2 element moves O(log n) instructions

Functions (Pop) l: Element index of the last leaf. m: Element index of the top element. i: Branch index of the first ancestor of the last leaf which has two children. j: The element index referred to by the first child of i. k: The element index referred to by i.

Functions (Pop) Case 1: m = l The top element is erased and the index values on the path from the new last leaf to the root are updated.

Functions (Pop) Case 2: m ≠ l and k ≠ l A[m] ← A[l] and the element stored at the last leaf is erased.  The content of the branches on the path from the leaf corresponding to the position m up to the root are updated.

Functions (Pop) Case 3: m ≠ l and k = l  A[m] ← A[j], A[j] ← A[l] and the element stored at the last leaf is erased.  The content of the branches on the path [i, root] are updated with a reference to j, if they earlier referred to the last leaf.  The content of the branches on the path from the leaf corresponding to the position m up to the root are updated.

Weight-biased leftist trees The structure of Weight-biased leftist trees. Nodes connected by pointers. Two pointers are used for each node. Two integer is used in every node to store the node’s right side and left side weight.

Weight-biased leftist trees Let T be an extended binary tree. For any internal node x of T, let LeftChild(x) and RightChild(x), respectively, denote the left and right children of x. The weight, w(x), of any node x is the number of internal nodes in the subtree with root x. Definition: A weight-biased leftist tree (WBLT) is a binary tree such that if it is not empty, then weight(LeftChild(x)) >= weight(RightChild(x)) for every internal node x.

Weight-biased leftist trees

Weight-biased leftist trees (Insert)

Weight-biased leftist trees (Delete- min)

Weight-biased leftist trees Space requirements Two pointers and two integers. Requirement on the number of Element comparisons. Top O(1) Pop (delete-min) 2log n Push (insert) log n

Programs STL binary heap Modified version of Weight-biased leftist trees by Seonghun Cho and Sartaj Sahni Navigation piles, programmed by me with an starting point in the algorithms presented in the article on Navigation piles by Jyrki Katajainen and Fabio Vitale.

Programs The navigation pile data structure was implemented in three different versions.  The first version used an STL vector to store the indices at the branches.  The second version used pointers instead of indices in an attempt to optimize the performance.

Programs  The third version packed the offsets as suggested in the original article by Jyrki Katajainen and Fabio Vitale. Offsets indicate the leaf position of the top element within the subtree rooted by the branch. The use of offsets instead of indices reduces the space required to 2N bits, where N is the capacity of the navigation pile.

Benchmarks Environment A  Intel computer:  CPU: Pentium 3 (1 GHz)  Main Memory: RAM 384 MB  Cache level 2: 246 KB  Operation system: Debian Sid  C++ Compiler: g++ 3.3

Benchmarks Environment B  Intel computer:  CPU: 2 * Pentium 4 (3 GHz)  Main Memory: RAM 1 GB  Cache level 2: 1024 KB  Operation system: Gentoo Linux r1  C++ Compiler: g

Benchmarks The input data is unsigned int. The benchmarks performed a construction operation followed by a series of pops. The CPH STL benchmark tool was used in the production of the benchmarks.

Fastest algorithm Which is the fastest algorithm, any guess?

Benchmarks (Intel P3)

Benchmarks (Intel P4)

Conclusion For integers, STL implicit binary heap is to fast for any ting I have found so far.

Ideas Other algorithms. Other benchmark strategies.

Benchmarks (input data) cheap move expensive move cheap comparison unsigned intbig int expensive comparison unsigned int ln comparison (int, big int) ln comparison