CSE 205 Lecture Notes - Lecture 27: Binary Tree, Heapsort, Binary Search Algorithm

236 views4 pages
CSE 205 Lecture 27 Heap and Heap Sort
A complete binary tree
o A binary tree in which every level, except possibly the last, is completely filled,
and all nodes are as far left as possible
Heaps
o Max-heap
A complete binary tree in which each element is greater than or equal to
both of its children
o Properties of a heap:
It is a complete binary tree
It has constraint on the elements stored at each node
o As with binary search trees, there are many possible heap configurations for a
given set of elements
o Heap operations work for:
Minheaps
Maxheaps
Keeps the largest value of a collection readily available
o Three primary operations for a Heap
Add new element to the heap
Find the maximum value
Remove the maximum value
Adding an Element to a Heap
o Add the element as a leaf, keeping the tree complete
o Then move the element up toward the root
Exchanging positions with its parents
Until the relationship among the elements is appropriate
o This will guarantee that the resulting tree will conform to the heap criteria
Removing the Largest Element from a Heap
o We know that the largest element in a heap can be found at the root
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents