Graphs & Trees
Graphs Nodes connected by Edges
Directed Graphs Directed Graph : Edges are one way
Trees Trees: A trunk from the roots Divides into branches Ends in leaves
Tree Strucures Directed graph with: Single root node with no parent Edge Node
Tree Strucures Directed graph with: Single root node (no parent) Parent nodes point to 1+ child nodes
Trees… Categorizations
Trees… Brackets
Trees… HTML documents
Trees… Image recognition
Expression Tree Represents mathematical expression (15 – 1) / 7
Expression Tree
Expression Tree
Traversal Most operations involve complete traversal
Traversal BinaryOp toString: Handle left child Handle self Handle right child
Traversal BinaryOp toString: Handleing may involve recursion Handle left child Handle self Handle right child Handleing may involve recursion
Traversal BinaryOp toString: Handle left child Handle self Handle right child
Traversal BinaryOp toString: Handle left child Handle self Handle right child
Traversal BinaryOp toString: Handle left child Handle self Handle right child
Traversal BinaryOp toString: Handle left child Handle self Handle right child
Traversal BinaryOp toString: Handle left child Handle self Handle right child
Traversal BinaryOp toString: Handle left child Handle self Handle right child
Traversal BinaryOp toString: Handle left child Handle self Handle right child
Traversal BinaryOp toString code Puts ( ) around node’s output
Traversal Most operations involve complete traversal Relative order of Left Self Right depends on job
Traversal Evaluate: Evaluate left Evaluate right Do math using left & right
Traversal Evaluate: Evaluate left Evaluate right Do math using left & right
Traversal Evaluate code