



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




2
" Submit regrades online " Regrades accepted until 10/
" e.g., [email protected] does not help us 3
General tree
Binary tree 5 4 7 8 Not a tree
List-like tree 4
! M is the root of this tree ! G is the root of the left subtree of M ! B, H, J, N, and S are leaves ! N is the left child of P; S is the right child ! P is the parent of N ! M and G are ancestors of D ! P, N, and S are descendants of W ! Node J is at depth 2 (i.e., depth = length of path from root = number of edges) ! Node W is at height 2 (i.e., height = length of longest path to a leaf) ! A collection of several trees is called a ...?
class GTreeCell { private Object datum; private GTreeCell left; private GTreeCell sibling; appropriate getter and setter methods }
General tree Tree represented using GTreeCell
7
8
Text AST Representation 9
10
public static boolean treeSearch(Object x, TreeCell node) { if (node == null) return false; if (node.datum.equals(x)) return true; return treeSearch(x, node.left) || treeSearch(x, node.right); } 9 8 3 5 7
" All left descendents of node come before node " All right descendents of node come after node
public static boolean treeSearch (Object x, TreeCell node) { if (node == null) return false; if (node.datum.equals(x)) return true; if (node.datum.compareTo(x) > 0) return treeSearch(x, node.left); else return treeSearch(x, node.right); }
" Pretend to look for the item " Put the new node in the place where you fall off the tree
" Tree uses alphabetical order " Months appear for insertion in calendar order jan feb mar apr jun may jul
19
" How can we keep it balanced? jan feb mar apr jun may jul
20
21
a cadabra$
bra ra cadabra$ dabra$ $ cadabra$ dabra$ cadabra$ (^) cadabra$ $
$ bra
22
23
s e a e t a s t 197 63 40 26
' 'e' ' (^242125139496 0010000001100101 33 ) 't' 'a' (^9566089651 0111010001100001 44 ) 'o' 'n' (^8888478465 0110111101101110 44 ) 'i' 's' (^7650573186 0110100101110011 44 ) 'h' 'r' (^6862568320 0110100001110010 55 ) 'l' 'u' (^5265732942 0110110001110101 56 ) 'g' 'f' (^2620125248 0110011101100110 66 ) '.' 'p' (^2136120661 0010111001110000 66 ) ... '7' '/' (^6858 0011011100101111 1515 ) 'X' '&' (^193 0101100000100110 1618 ) '%' '+' (^32 0010010100101011 1919 ) original compressed size size (^119043206822151) 42.7% compression 24