Post krealloc demo Tree notes: You know how they work already Let's make one! Considerations: It'll be a C++ ADT, like we've been doing This time I want a key/value tree key: Used for ordering and finding nodes value: Can be retrieved given the key Search given key must be O(log(n)) Search given value can be O(n), like a linked list We'll do a template class It'll be a red/black tree We won't use the example from last term But we'll probably steal the tree visualization bit Practicalities: Red/Black trees tend to have some bugs I'm going to add a couple active learning debugger exercises So log into isoptera. We'll use /tmp for shared code Limitation: 1 value per node Just to keep our heads screwed on straight Required operations: key: Can we standardize on two comparisons? value: Just need to be able to get back a reference A set would just have keys Project 2 describes a tree with just values, not key/value pairs Iterator-based traversal: Should all four ways be available? inorder: It's good to print out values in order postorder: We'll need one for the destructor anyway preorder: Maybe less appealing It's good for duplication Also good for expression parsing, but we probably won't do that breadth-first: log(n) memory, log(n^2) if fully unbalanced We won't be fully unbalanced anyway With limited depth, it'll give distributed samples Can be used to print tree structure Good lab idea! Operators and Methods: add, remove, accessor for size begin and end for inorder traversal For a key/value tree, operator[] is sort of expected Can it be used to add a new value? Some libraries do this. I'd like operator<<, mostly just for debugging write_graph or something to do graph output Parent pointers: Could we do without? Let's see what trouble we run into!