04 - Heapsort Data Structures and Algorithms Andrei Bulatov...

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

View Full Document Right Arrow Icon
Heapsort Data Structures and Algorithms Andrei Bulatov
Background image of page 1

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

View Full DocumentRight Arrow Icon
Algorithms – Heapsort 4-2 Heap Property A heap is a nearly complete binary tree, satisfying an extra condition Let Parent(i) denote the parent of the vertex i Max-Heap Property : Key(Parent(i)) Key(i) for all i in eap Property Min-Heap Property : Key(Parent(i)) Key(i) for all i 1 4 2 3 9 7 8 14 10 16
Background image of page 2
Algorithms – Heapsort 4-3 Heaps Nearly complete binary tree means that the length of any path from the root to a leaf can vary by at most one The height of a vertex i is the length of the longest simple downward path from i Therefore the height of the root is around log n
Background image of page 3

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

View Full DocumentRight Arrow Icon
Algorithms – Heapsort 4-4 Heap Operations Creating a max-heap Accessing the maximal element (root) Inserting an element eleting an element Goal running time O(n) O(1) O(log n) (log n) Deleting an element O(log n)
Background image of page 4
4-5 Implementing Heaps and Operations Heap can be implemented by an array 16 14 10 8 7 9 3 2 4 1 Children: leftChild(i) = 2i
Background image of page 5

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

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

This note was uploaded on 11/19/2009 for the course CS CMPT 307 taught by Professor A.bulatov during the Fall '09 term at Simon Fraser.

Page1 / 14

04 - Heapsort Data Structures and Algorithms Andrei Bulatov...

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

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