20_priority_queues_II - CSCI-1200 Data Structures Fall 2010...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSCI-1200 Data Structures Fall 2010 Lecture 20 Priority Queues and Leftist Heaps Review from Lecture 21 Operators as non-member functions, as member functions, and as friend functions. Queues and Stacks, Whats a Priority Queue? A Priority Queue as a Heap, percolate_up and percolate_down A Heap as a Tree (with nodes & pointers) Todays Class A Heap as a Vector Building a Heap Heap Sort Merging heaps are the motivation for leftist heaps Mathematical background & Basic algorithms Homework 6 Contest Results! 20.1 Vector Implementation In the vector implementation, the tree is never explicitly constructed. Instead the heap is stored as a vector, and the child and parent pointers can be implicitly calculated. To do this, number the nodes in the tree starting with 0 first by level (top to bottom) and then scanning across each row (left to right). These are the vector indices. Place the values in a vector in this order. As a result, for each subscript, i , The parent, if it exists, is at location b ( i- 1) / 2 c . The left child, if it exists, is at location 2 i + 1. The right child, if it exists, is at location 2 i + 2. For a binary heap containing n values, the last leaf is at location n- 1 in the vector and the last internal (non-leaf) node is at location b ( n- 1) / 2 c . The standard library (STL) priority_queue is implemented as a binary heap....
View Full Document

This note was uploaded on 02/21/2012 for the course CSCI 1200 taught by Professor Cutler during the Fall '08 term at Rensselaer Polytechnic Institute.

Page1 / 4

20_priority_queues_II - CSCI-1200 Data Structures Fall 2010...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online