Week 9
Quiz
Trees
· node, root, left & right child, parent, leaf, sub-tree, depth, complete
· e.g. medical 20 questions
· e.g. sorted list
· root =[0], children of i = [2i+1],[2i+2], parent of i = [(i-1)/2]
· limited by array, must be complete, etc.
· draw picture
· define class structure
will be a big deal to decide if things go in node or tree class
can also use a static class
· basic ops, e.g.
isleaf(),
add(),
copytree(tnode
· draw pictures of operations remove and add
· lots of cases for remove node
· show code for simple removal
· do remove rightmost();
public node remrightmost()
{
if(right == null)
return(left);
else
right = right.remrightmost()
return this;
· show how this works recursively, show stack
public void printtree()
{
print node;
if(left != null)
left.printtree();
if(right != null)
right.printtree();
}