0% found this document useful (0 votes)
29 views23 pages

Trees

A spanning tree of a graph is a subgraph that is a tree containing every vertex of the graph. Depth-first search and breadth-first search can both be used to find a spanning tree. For depth-first search, a root is chosen and edges are added to form paths, backtracking when needed to include all vertices. For breadth-first search, a root is chosen and its incident edges added, then the neighbors' incident edges are added without circuits at each level until all vertices are included.

Uploaded by

Ezgi Bulut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views23 pages

Trees

A spanning tree of a graph is a subgraph that is a tree containing every vertex of the graph. Depth-first search and breadth-first search can both be used to find a spanning tree. For depth-first search, a root is chosen and edges are added to form paths, backtracking when needed to include all vertices. For breadth-first search, a root is chosen and its incident edges added, then the neighbors' incident edges are added without circuits at each level until all vertices are included.

Uploaded by

Ezgi Bulut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Graph Theory

Trees
A tree is a connected undirected graph with no simple circuits.

G1 and G2 are trees, because both


are connected graphs with no simple
circuits. G3 is not a tree because e, b,
a, d, e is a simple circuit in this graph.
A rooted tree is a tree in which one vertex has been designated as the root and every
edge is directed away from the root.
The terminology for trees has botanical and genealogical origins. Suppose that T is a
rooted tree. If v is a vertex in T other than the root, the parent of v is the unique vertex u
such that there is a directed edge from u to v. When u is the parent of v, v is called a
child of u. Vertices with the same parent are called siblings. The ancestors of a vertex
other than the root are the vertices in the path from the root to this vertex,
excluding the vertex itself and including the root. The descendants of a vertex v are
those vertices that have v as an ancestor. A vertex of a rooted tree is called a leaf if it has
no children. Vertices that have children are called internal vertices.
The parent of c is b. The
children of g are h, i, and j .
The siblings of h are i and j .
The ancestors of e are c, b,
and a. The descendants of b
are c, d, and e. The internal
vertices are a, b, c, g, h, and
j . The leaves are d, e, f , i, k,
l, and m.
A rooted tree is called an m-ary tree if every internal vertex has no more than m children.
The tree is called a full m-ary tree if every internal vertex has exactly m children. An m-ary
tree with m = 2 is called a binary tree.

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.

What is the prefix form for ((x + y) ↑ 2) + ((x − 4)/3)?

We obtain the prefix form for this expression by traversing the


binary tree that represents it in preorder, This produces
+ ↑ + x y 2 / − x 4 3.
What is the value of the prefix expression + − ∗ 2 3 5/↑ 2 3 4?
We obtain the postfix form of an expression by traversing its binary tree in postorder.
Expressions written in postfix form are said to be in reverse Polish notation. Expressions in
reverse Polish notation are unambiguous, so parentheses are not needed

What is the postfix form of the expression ((x + y) ↑ 2) + ((x − 4)/3)?

The postfix form of the expression is obtained by carrying out a


postorder traversal of the binary tree for this expression. This
produces the postfix expression:
xy + 2 ↑ x 4 − 3 / +.
What is the value of the postfix expression 7 2 3 ∗ − 4 ↑ 9 3/+?
Consider the system of roads in Maine represented by the simple graph. The only way
the roads can be kept open in the winter is by frequently plowing them. The highway
department wants to plow the fewest roads so that there will always be cleared roads
connecting any two towns. How can this be done?

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.

Find a spanning tree of the simple graph G.


We can build a spanning tree for a connected simple graph using depth-first search. We will form a rooted tree, and
the spanning tree will be the underlying undirected graph of this rooted tree. Arbitrarily choose a vertex of the graph
as the root. Form a path starting at this vertex by successively adding vertices and edges, where each new edge is
incident with the last vertex in the path and a vertex not already in the path. Continue adding vertices and edges to
this
path as long as possible. If the path goes through all vertices of the graph, the tree consisting of this path is a spanning
tree. However, if the path does not go through all vertices, more vertices and edges must be added. Move back to the
next to last vertex in the path, and, if possible, form a new path starting at this vertex passing through vertices that
were not already visited. If this cannot be done, move back another vertex in the path, that is, two vertices back in the
path, and try again.
Spanning tree
We can also produce a spanning tree of a simple graph by the use of breadth-first search. Again, a rooted tree will
be constructed, and the underlying undirected graph of this rooted tree forms the spanning tree. Arbitrarily choose
a root from the vertices of the graph. Then add all edges incident to this vertex. The new vertices added at this stage
become the vertices at level 1 in the spanning tree. Arbitrarily order them. Next, for each vertex at level 1, visited in
order, add each edge incident to this vertex to the tree as long as it does not produce a simple circuit.
Arbitrarily order the children of each vertex at level 1. This produces the vertices at level 2 in the tree. Follow the
same procedure until all the vertices in the tree have been added. The procedure ends because there are only a
finite number of edges in the graph. A spanning tree is produced because we have produced a tree containing every
vertex of the graph.
Spanning tree

You might also like