Tree - in “math speak” An ________ graph is a set of vertices/nodes and a set of edges, each edge connects two vertices. Any undirected graph in which every two vertices are connected by exactly one path (sequence of edges & associated vertices) is a ______.
Tree - more properties A tree is a minimally connected graph (i.e., all vertices are connected by paths, but removing any edge disconnects) A tree is a connected graph with one less edge than vertex. A tree is a maximally acyclic graph (i.e., it contains no cycles, but adding another edge creates one or more cycles)
Changing Tree Geometry This is a typical tree to a computer scientist. properties: ______ _______ Vertices are often called _____.
The extreme “ends” of a tree A ____is a node at the extreme end of a path from the root (i.e., there are no edges to allow the path to continue). Identify the leaves in the following trees.
Trees can be taller/shorter A _______of a tree is the number of nodes in its longest path from root to leaf.
Directed Trees Tree edges are directed from the root outward. A ______node shares an edge with every ______. The parent is “closer to” the root. Def’n: rooted (directed) tree Every node, except the root, has exactly one parent. Def’n: rooted (directed) tree Every node, except the root, has exactly one parent.
The tree’s “extended family” If n 1 is the parent of n 2, then n 1 is n 2 ’s ancestor. ancestor If n 1 is the parent of n a and n a is an ancestor of n 2, then n 1 is n 2 ’s ancestor. If n 1 is the ancestor of n 2, then n 2 is n 1 ’s descendant. descendant The level of a node is the number of edges in its path to the root. level
Subtrees Any node of a tree, together with all of its descendants and associated edges, forms a subtree. subtree Example: the subtree rooted at F
Expression Trees - An Application An expression tree is a tree in which a node contains either an operand or operator and each subtree represents a subexpression of the whole. Example: (1 + 2) * (3 - 4) / -(5 * 6)
Decision Trees - Another Application A decision tree maintains yes/no questions in each non-leaf node, and each left subtree is for “no” while the right subtree is for “yes”. Example