notes17

notes17 - Class Notes for Sept. 08 2009, Rodrigo Haragutchi...

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

View Full Document Right Arrow Icon
Class Notes for Sept. 08 2009, Rodrigo Haragutchi Priority Queues a data structure that supports the methods: o insert(k,e) - inserts a pair key "k" and element "e" in the priority queue o (k,e)RemoveMin() - returns a pair(k,e) where k is the key with the min  value the key can be a numeric value, a string, etc the comparison function used to get a key can be a numeric  comparison(ascending, descending) or alphabetical.  Heaps: implementation of a priority queue using an away/binary tree. A heap is a binary tree where the key of the parent is smaller than the key of the  children. also a heap is "left-filled", that is, all the rows and all the levels are full except the  last one where all the leafs are shifted to the left 3 / \ 5 7 This is a correct heap. / \ 8 10 7 / \ 3 8 This is not. / \ 5 9 for all nodes, parent < child All levels are full; on the external level, the children are shifted to the left Operations in a heap Insert: 3 / \ 5 7 / \ 8 10
Background image of page 1

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

View Full DocumentRight Arrow Icon
(we want to insert a  2 ) we will insert the new element in the next available position in the bottom level.  3 / \ 5 7 But This is not a heap! / \ / 8 10 2 we need to fix the heap by applying the upheap mechanism that starting at the  inserted node, swaps the node with the parent if the child is smaller than the  parent. We continue up to the root if necessary.  3 / \ 5 7
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 7

notes17 - Class Notes for Sept. 08 2009, Rodrigo Haragutchi...

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