Nov 2, 2001CSE 373, Autumn Hash Table example marking deleted items + choice of table size
Nov 2, 2001CSE 373, Autumn Priority Queue ADT Checkout line at the supermarket Printer queues operations: insert, deleteMin insertdeleteMin
Nov 2, 2001CSE 373, Autumn Simple implementations of the Priority Queue ADT insertdeleteMin list sorted list BST AVL tree (overkill?)
Nov 2, 2001CSE 373, Autumn Binary heaps Structure property Perfect binary tree – all leaves are at the same depth height h 2 h+1 – 1 nodes 2 h – 1 non-leaves 2 h leaves
Nov 2, 2001CSE 373, Autumn Complete binary tree of height h For h = 0, just a single node. For h = 1, left child or two children. For h 2, either –the left subtree of the root is perfect with height h-1 and the right is complete with height h-1, OR –the left is complete with height h- 1 and the right is perfect with height h-2.
Nov 2, 2001CSE 373, Autumn Structure, continued Informally: A perfect binary tree of height h-1 with leaves added at height h in the leftmost positions. N-node heap of height h: h = log N 2 h N 2 h+1 - 1
Nov 2, 2001CSE 373, Autumn Representing Complete Binary Trees G ED CB A JKHI F L From node i, left child: right child: parent: ABCDEFGHIJKL implicit (array) implementation:
Nov 2, 2001CSE 373, Autumn Why is it better? no pointers (space). *2, /2, + are faster operations than dereferencing a pointer. can get to parent easily Can we use the implicit representation for binary search trees?