CSE116 4-21-2010 Notes

CSE116 4-21-2010 Notes - The tree is heap ordered Balance...

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

View Full Document Right Arrow Icon
Priority Queues A priority queue is a queue in which items are ordered according to their priorities. Traditionally, low numeric values for priorities correspond to high priorities. Implementation Linear list – sorted list in which items are ordered by priority Heap - A binary tree which maintains its items according to a heap order Aside : the queue we saw earlier is a special case of a priority queue in which the priority of an item corresponds to how long it has been in the queue. A head is a binary tree that maintains two invariants: 1) Order property 2) Structure/balance property Heap order Property (min version) For every non-empty heap the value at the root is less than any value in either of its children.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The tree is heap ordered Balance Property Basic idea : do not start a new level in the tree until the previous one is full In our implementation, the condition is: For every non-empty heap, the size of the left subtree is either the same size as the right subtree, r it is one larger Either: |L| = |R| Or: |L| = |R| + 1 Insertion into a heap: 1a) insert a new item (recursively) into the right subtree 1b) swap the left and right subtrees as we go along 2) Restore the order condition by percolating up any out – of –order item along the insertion path Ex: show what an initially empty min- heap looks like as each of the following items is inserted: 40 60 90 50 20 30 10 D) …...
View Full Document

This document was uploaded on 12/11/2011.

Page1 / 3

CSE116 4-21-2010 Notes - The tree is heap ordered Balance...

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

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