{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

Heapsort Data Structures and Algorithms Andrei Bulatov

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

View Full Document
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 Min-Heap Property : Key(Parent(i)) Key(i) for all i 1 4 2 3 9 7 8 14 10 16
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

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

View Full Document
Algorithms – Heapsort 4-4 Heap Operations Creating a max-heap Accessing the maximal element (root) Inserting an element Deleting an element Goal running time O(n) O(1) O(log n) O(log n)
Algorithms – Heapsort 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 rightChild(i) = 2i + 1 Parent: parent(i) = i / 2 Length: length(H) = the number of elements in H

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online