Tutorial 4

advertisement
SUBJECT: DISCRETE STRUCTURE & APPLICATIONS
CODE: BCT2083
FACULTY OF INDUSTRIAL
SCIENCES & TECHNOLOGY
TOPIC: Chapter 4 Trees
TUTORIAL 4
DURATION: 3 weeks (week 12-13)
Week 12
1.
Consider the following tree
a
b
c
e
f
g
d
h
i
j
j
(a)
(b)
(c)
(d)
(e)
(f)
(g)
2.
Suppose that the universal address set address of a vertex v in an ordered rooted tree is
32515. Find
(a)
(b)
(c)
(d)
3.
Find the parents of c and h.
Find the ancestors of c and of j.
Find the children of d and of e.
Find the descendants of c and of e.
Find the siblings of f and of h.
Find the internal vertices.
Find the leaves.
the level of v.
the minimum number of siblings of v.
the address of the parent of v.
the minimum number of vertices in the tree.
Suppose you have 50 coins, one of which is counterfeit (either heavier or lighter than the
others). You use a pan balance scale to find the bad coin. Prove that 4 weighings is not enough
to guarantee that you find the bad coin and determine whether it is heavier or lighter than the
other coins.
Week 13
4.
(a) Set up a binary tree for the following list, in the given order, using alphabetical ordering:
STOP, LET, THERE, TAPE, NONE, YOU, ANT, NINE, OAT, NUT.
(b) Explain step by step how you would search for the word TEST in your tree.
i.
ii.
iii.
iv.
What is the height of the shortest binary search tree that can hold all 10 words?
Write the preorder traversal of the tree.
Write the postorder traversal of the tree.
Write the inorder traversal of the tree.
BCT2083
5.
Tutorial 4
(a) Set up a binary tree for the following list, in the given order, using alphabetical ordering:
SHE, SELLS, SEA, SHELLS, BY, THE, SEASHORE.
(b) How many comparisons with words in the tree are needed to determine if the word
SHARK is in the tree?
(c) How many comparisons with words in the tree are needed to determine if the word
SEAWEED is in the tree?
(d) How many comparisons with words in the tree are needed to determine if the word
CONCH is in the tree?
6.
Draw a derivation tree for (a  (3  2b))(c2  d).
7.
Find the preorder traversal of the parsing tree for (8 x  y )5  7 4 z  3 .
8.
Find the postorder traversal of the parsing tree for (8 x  y )5  7 4 z  3 .
9.
Find the inorder traversal of the parsing tree for (8 x  y )5  7 4 z  3 .
10.
In the questions below refer to the given tree.
(a)
(b)
(c)
Find the preorder traversal.
Find the inorder traversal.
Find the postorder traversal.
11.
The algebraic expression    a  7c34  3b is written in prefix notation. Write the expression
in postfix notation.
12.
Write the compound proposition (p)  (q  (r  s)) in postfix notation.
13.
Write the compound proposition (p)  (q  (r  s)) in prefix notation.
14.
Write the compound proposition (p)  (q  (r  s)) in infix notation.
15.
The string 2 3 a  x  4   7  is postfix notation for an algebraic expression. Write the
expression in prefix notation.
2
BCT2083
Tutorial 4
16.
The string 2 3 a  x  4   7  is postfix notation for an algebraic expression. Write the
expression in infix notation.
17.
The string   2  x a  4 y is prefix notation for an algebraic expression. Write the expression
in postfix notation.
18.
The string   2  x a  4 y is prefix notation for an algebraic expression. Write the expression
in infix notation.
19.
Find the value of   x  5 t  4  7 c (in prefix notation) if c  5, x  2, and t  1.
20.
Find a minimal spanning tree for this weighted graph using Prim's algorithm.
21.
Use Prim's algorithm to find a minimal spanning tree for this weighted graph. Use
alphabetical order to break ties.
22.
Find a spanning tree of minimum cost for this graph.
3
BCT2083
23.
Tutorial 4
Find a spanning tree of the following graph. Use Prim’s algorithm and Kruskal’s algorithm.
(a)
A
B
8
7
3
7
C
D
5
4
9
6
4
E
F
(b)
A
B
4
7
7
8
C 7
4
12
8
E
6
5
9
F
4
D
G
10 H
ANSWERS CHAPTER 4: Trees
1. a) b, d
b) b a, e c a
c) h i, j d) e f g j, j e) e g, i
f) a b c d g) j f g b h i
2. (a) 5. (b) 4. (c) 3251. (d) 17.
3. Four weighings yield a 3-ary tree of height 4, which has at most 81 leaves. Fifty coins require a
tree with 100 leaves.
4. (a)
(b) i.
ii.
iii.
iv.
3
STOP, LET, ANT, NONE, NINE, OAT, NUT, THERE, TAPE, YOU.
ANT, NINE, NUT, OAT, NONE. LET, TAPE, YOU, THERE, STOP.
ANT, LET, NINE, NONE, NUT, OAT, STOP, TAPE, THERE, YOU.
4
BCT2083
5.
Tutorial 4
(a)
(b) 2. (c) 4. (d) 4.
6.
    8 xy5  7
 4 z3
7.
8.
8 x  y  5  4 z  3  
9.
8 x  y  5  7  4 z  3
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
a) dbacefghiljmknop
a7c  3  4  3b  
pqrs
pqrs
pqrs
23ax47
23ax47
2xa4y
2xa4y
30
17
9
24
a) 24
b) 38

b) abcfegdihjlkmnop
c) acfgebijknmoplhd
5
Download