which each node has a greater (or equal) priority value than its children • A more accurate name for this is max heap • If each node has a priority value less than its children, it is called a min heap
root node to current node • For example, the root is at depth 0, its children at depth 1, their children are at depth 2, etc. • Nodes on the same level have the same depth
binary tree, it is convenient to implement with an array Next node that is added is put at end of array • If the parent node has array index i Then left child is at index 2*i+1 And right child is at index 2*i+2
node relationship of the max heap intact, the new node is swapped with its parent, until the parent node is larger than the child node (“trickles up” the tree) Each node in a max heap has a larger value than its two child nodes
heap follows a path from the leaf to the root A maximum of h comparisons have to be made, where h is the height of the tree The height of a complete binary tree (heap) is log2 n (n is number of nodes) Therefore, the Big-O is O(log n)
always from the top • Step 1: The top node is deleted and its value returned The deleted node is replaced with the rightmost, bottommost node This maintains the heap as a complete binary tree
value at top of tree, the new value must be compared to its children If it is smaller than its largest child node, it is swapped with its largest child node So the node “trickles down” the tree
heap follows a path from the root to the leaf A maximum of h comparisons have to be made, where h is the height of the tree The height of a complete binary tree (heap) is log2 n (n is number of nodes) Therefore, the Big-O is O(log n)
1.Do the assignment corresponding to this lecture 2.Email me any questions you may have about the material 3.Turn in the assignment before the due date 4.Stop playing video games!