Professional Documents
Culture Documents
All the graphs shown in Figure 10.5.1 are trees, whereas those in Figure 10.5.2 are not.
Example 10.5.1 Trees and Non-Trees
Example 10.5.1 Trees and Non-Trees
All the graphs shown in
AllFigure 10.5.1shown
the graphs are trees, whereas
in Figure those
10.5.1 areintrees,
Figure 10.5.2those
whereas are not.
in Figure 10.5.2 are not.
In mathematics, a tree is a connected graph that does not
contain any circuits.
developed grammars to describe the syntax of natural customary to express them using the shorthand notation
Score on = 8, 9, 10 Score on
part I part II
≤6 Math 100
part I part II
part II Figure 10.5.3
≤6 Math 100
≤ 10 Math 110
Solution <8the student scored 9 on part I, the score on part II is checked. Since it is
Since
This work has proved useful in constructing compilers for >10 Math
greater than 6, the student should be100
advised to take Math 110. ■
Figure 10.5.3
high level computer languages. Example 10.5.3 A Parse Tree
Solution In the
Since the last 30 scored
student years, Noam
9 onChomsky andscore
part I, the othersonhave developed
part new waysSince
II is checked. to describe
it is the
greater than 6, syntax (or grammatical
the student should bestructure)
advised of take>6
to natural languages
Math 110. suchMath
as English.
110 As is discussed
■
briefly in Chapter 12, this work has proved useful in constructing compilers for high-
Score on = 8, 9, level
10 computer Score on In the study of grammars, trees are often used to show the
languages.
In the study of grammars, trees are often used to show the Examplepart I
10.5.3 part II
A Parse Tree derivation of grammatically correct sentences from certain basic rules. Such trees are
≤ trees.
called syntactic derivation trees or parse 6 Math 100
In the last 30 years, Noam Chomsky and others have developed new ways to describe the
derivation of grammatically correct sentences from certain syntax (or grammatical structure) of natural languages such as English. As is discussed
<8in Chapter 12, this work has proved useful in constructing compilers for high-
briefly
basic rules. Such trees are called derivation trees or level computer languages. In Math
Editorial review has deemed that any suppressed content does not materially affect the overall learning100
the study of grammars, trees are often used to show the
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
derivation of grammatically correct sentences from certain basic rules. Such trees are
parse trees. called syntactic derivation Figure trees10.5.3 or parse trees.
Solution Since the student scored 9 on part I, the score on part II is checked. Since it is
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
greater than 6, the student should be advised to take Math 110. ■
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
6 7
In the notation, the symbol | represents the word or, and There is a somewhat surprising relation between the
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
angle brackets are used to enclose terms to be defined number of vertices and the number of edges of a tree. It
(such as a sentence or noun phrase). turns out that if n is a positive integer, then any tree with
n vertices (no matter what its shape) has n – 1 edges.
The derivation of the sentence 䇾The young man caught the
ball䇿 from the mentioned rules is described by the tree
shown below. Perhaps even more surprisingly, a partial converse to this
fact is also true—namely, any connected graph with
n vertices and n – 1 edges is a tree.
It follows from these facts that if even one new edge (but no
new vertex) is added to a tree, the resulting graph must
contain a circuit.
8 10
Characterizing Trees Characterizing Trees
Also, from the fact that removing an edge from a circuit An important fact necessary to derive the first main
does not disconnect a graph, it can be shown that every theorem about trees is that any nontrivial tree must have at
connected graph has a subgraph that is a tree. least one vertex of degree 1.
11 12
13 14
Proof by Induction.
Basis case: For n=1 the property holds since there are no
Solution: loops.
The terminal vertices are v0, v2, v4, v5, v7, and v8. Inductive Step: Let T be an arbitrarily chosen tree with k + 1
vertices, for k ! 1. Since k+1>1, by Lemma 10.5.1, T has a
vertex v of degree 1. Since T is connected, v is attached to
The internal vertices are v6, v1, and v3. the rest of T by a single edge e as sketched in the following
15 figure. 16
Theorem 10.5.2 Example 7 – Finding Trees Satisfying Given Conditions
Solution:
• By Theorem 10.5.2, any tree with 4 vertices has 3 edges;
• Thus, by the Handshake Theorem (10.1.1), the total
Now if e and v are removed from T, what remains is a tree T’ degree of a tree with four vertices must be 6;
with (k + 1) " 1 = k vertices and, by inductive hypothesis, T’ • Also, every tree with more than one vertex has at least
has k " 1 edges. But the original tree T has one more vertex
two vertices of degree 1.
and one more edge than T’. Hence T must have (k " 1) + 1 =
k edges, as was to be shown.
17 18
1, 1, 1, 3 and 1, 1, 2, 2.
There are two non-isomorphic trees corresponding to both Essentially, the reason why Lemma 10.5.3 is true is that
of these possibilities, as shown below. any two vertices in a circuit are connected by two distinct
paths.
The following is an example of a graph with five vertices In mathematics, a rooted tree is a tree in which one vertex
and four edges that is not a tree. By Theorem 10.5.4, such has been distinguished from the others and is designated
a graph cannot be connected. the root.
A Rooted Tree
26 Figure 10.6.1 27
b. 0
a. What is the level of v5?
b. What is the level of v0? c. 3
c. What is the height of this rooted tree? d. v5 and v6
d. What are the children of v3?
e. v0
e. What is the parent of v2?
f. What are the siblings of v8? f. v7 and v9
28 29
Rooted Trees Binary Trees
Note that in the tree with root v0 shown below, v1 has level When every vertex in a rooted tree has at most two children
1 and is the child of v0, and both v0 and v1 are terminal and each child is designated either the (unique) left child or
vertices. the (unique) right child, the result is a binary tree.
30 32
These terms are illustrated in Figure 10.6.2. Binary trees are used in many ways in computer science.
One use is to represent algebraic expressions with arbitrary
nesting of balanced parentheses. For instance, the
following (labeled) binary tree represents the expression a/
b: The operator is at the root and acts on the left and right
children of the root in left-right order.
A Binary Tree
Figure 10.6.2
33 34
An interesting theorem about full binary trees says that if Is there a full binary tree that has 10 internal vertices and
you know the number of internal vertices of a full binary 13 terminal vertices?
tree, then you can calculate both the total number of
vertices and the number of terminal vertices, and Solution:
conversely. More specifically, a full binary tree with k
No. By Theorem 10.6.1, a full binary tree with 10 internal
internal vertices has a total of 2k + 1 vertices of which k + 1
are terminal vertices. vertices has 10 + 1 = 11 terminal vertices, not 13.
Characterizing Binary Trees Example 4 – Determining Whether a Certain Binary Tree Exists
Another interesting theorem about binary trees specifies Is there a binary tree that has height 5 and 38 terminal
the maximum number of terminal vertices of a binary tree of vertices?
a given height.
The maximum number of terminal vertices of a binary tree Solution:
of height h is 2h. Another way to say this is that a binary No. By Theorem 10.6.2, any binary tree T with height 5 has
tree with t terminal vertices has height of at least log2t.
at most 25 = 32 terminal vertices, so such a tree cannot
have 38 terminal vertices.
#$%&'()݄
*$+&+),-
݊ ൌ ͳ ʹ Ͷ ͺ ʹ ൌ ʹାଵ െ ͳ
! "
4"#"060'#607)%'-8'#-.)/'"#'$'7"#$%&'(%))9 01233))456$$7589
45:;<$758)))6;;(=)
>
#$%&'()݄ 01233))45:;<$7589)))
*$+&+),-
5) $=
45:;<$758) 1$?(0'%1<=
45:;<$758)) 6%&'(0'%1<=
>
@)
݊ ൌ݄ͳ @
. /
!"#$%&':%))':%$;)%/$2''<.)=(,'8"%/(> !"#$%&':%))':%$;)%/$2''<.)=(,'8"%/(>
G;;($<)(6$$))))))))))))))))))))))))))))))))))))))))4%C26E)(6$$)) G;;($<)(6$$))))))))))))))))))))))))))))))))))))))))4%C26E)(6$$))
*123()1$0(H6$- *123()1$0(H6$-
A I
B6$;6<$645 *6;;(-9))))) B;3(;6<$645 *6;;(-9)))))
%?)*6;;()%3)C;()$DB(E-9 %?)*6;;()%3)C;()$DB(E-9 ?5$0=2)
F%3%()6;;())))))))))))))))))))))))) B;3(;6<$645*6;;(+1$?(-
B6$;6<$645*)6;;(+1$?( - B;3(;6<$645*6;;(+6%&'(-
B6$;6<$645*)6;;(+6%&'( - F%3%()6;;(
@ @ 2
@ @ N6$);6<$6>)))))))))))2M<$0?&
M 0
OC);6<$6>))))))))))))))<$M2?0&
%C;6<$645 *6;;(-9)))))
< ? & N;3();6<$6>))))))))))$<M?&02
%?)*6;;()%3)C;()$DB(E-9
%C;6<$645*6;;(+1$?(-
F%3%()6;;( $
%C;6<$645*6;;(+6%&'(-
@
@
J KL
?5$0=2)'-8'7"#$%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