Trees
Trees
Trees
A tree is a connected undirected graph with no simple circuits.
3-ary tree
A Binary tree
Let T be an ordered rooted tree with root r. If T consists only of r, then r is the preorder
traversal of T . Otherwise, suppose that T1, T2, . . . , Tn are the subtrees at r from left to
right in T . The preorder traversal begins by visiting r. It continues by traversing T1 in
preorder, then T2 in preorder, and so on, until Tn is traversed in preorder.
Let T be an ordered rooted tree with root r. If T consists only of r, then r is the inorder
traversal of T . Otherwise, suppose that T1, T2, . . . , Tn are the subtrees at r from left to
right. The inorder traversal begins by traversing T1 in inorder, then visiting r. It continues
by traversing T2 in inorder, then T3 in inorder, . . . , and finally Tn in inorder
Let T be an ordered rooted tree with root r. If T consists only of r, then r is the postorder
traversal of T . Otherwise, suppose that T1, T2, . . . , Tn are the subtrees at r from left to
right. The postorder traversal begins by traversing T1 in postorder, then T2 in postorder, . . . ,
then Tn in postorder, and ends by visiting r.
We can represent complicated expressions, such as compound propositions, combinations of sets,
and arithmetic expressions using ordered rooted trees. For instance, consider the representation
of an arithmetic expression involving the operators + (addition), − (subtraction), ∗ (multiplication),
/ (division), and ↑ (exponentiation). We will use parentheses to indicate the order of the
operations. An ordered rooted tree can be used to represent such expressions, where the internal
vertices represent operations, and the leaves represent the variables or numbers. Each operation
operates on its left and right subtrees (in that order).
What is the ordered rooted tree that represents the expression
((x + y)↑2) + ((x − 4)/3)?
An inorder traversal of the binary tree representing an expression produces the original
expression with the elements and operations in the same order as they originally occurred, For
instance, inorder traversals of the binary trees , which represent the expressions (x + y)/(x + 3),
(x + (y/x)) + 3, and x + (y/(x + 3)), all lead to the infix expression x + y/x + 3. To make such
expressions unambiguous it is necessary to include parentheses in the inorder traversal
whenever we encounter an operation. The fully parenthesized expression obtained in this way
is said to be in infix form.
We obtain the prefix form of an expression when we traverse its rooted tree in preorder.
Expressions written in prefix form are said to be in Polish notation, which is named after the
Polish logician Jan Lukasiewicz. An expression in prefix notation, is unambiguous, so no
parentheses are needed in such an expression.
At least five roads must be plowed to ensure that there is a path between any two towns.
Let G be a simple graph. A spanning tree of G is a subgraph of G that is a tree
containing every vertex of G.