Tentamen/Exam TDDC32 Design och implementering av programmodul i Java

advertisement
Tentamen/Exam
TDDC32 Design och implementering av
programmodul i Java
TDDC32 Design and implementation of
a software module in Java
2010–06–11
08.00 – 12.00
• No help materials are allowed, except for an English dictionary.
• You may answer in Swedish or English.
• Total number of credits is 26. Limits:
3: 13p, 4: 17, 5: 21p.
• Jour (person on duty): Jonas Wallgren, tel. 013-178594
(endast telefonjour (only by phone))
1
1
OOA&OOD
Explain what is ment in OOA and OOD by the following concepts/”slogans”:
a)(1.5p) Divide and conquer
b)(1.5p) Iterate and increment
c)(1.5p) Reuse and recycle
d)(1.5p) Strong cohesion and low coupling
2
UML
Describe the following situation using a class diagram (3p):
A Mammal is an Animal.
A Bird is an Animal.
A Wild animal is an Animal.
A Domestic aninmal is an Animal.
A Rabbit is a Wild Mammal.
A Hen is a Domestic Bird.
A Fox is a Wild Mammal.
An Eagle is a Wild Bird.
All Birds have 2 legs.
All Mammals have 4 legs.
Predatory animals are animals.
Preys are animals.
All Predatory animals can have several possible Preys and some specific favourite Prey.
(Eagles prey on Foxes and Hens, and Foxes prey on Hens.)
2
3
AVL
a)(2p) Construct an AVL tree from the keys (in the given order) 4 6 9 11 3 5 10 8 7.
You don’t need to draw every intermediate tree. Every time there has been a
rebalancing you should draw the resulting tree.
b)(1p)What is a Fibonacci tree and what is it used for?
4
Splay
a)(1p) When is a splay tree better than an AVL tree and why is it better?
b)(2p) Construct a splay tree from the keys (in the given order) 4 5 6 7 1 2 3.
Show the tree after each insertion is completed.
5
(a,b)-tree
a)(1.5p) Show what happens step by step when you remove the values 40, 39, 3
from the following (2,4)-tree:
+----+
| 20 |
+----+
/
\
/
\
+----+
+----+----+----+
| 10 |
| 30 | 40 | 50 |
+----+
+----+----+----+
|
|
/
|
\
\
+---+ +----+ +----+ +----+ +----+ +----+
| 3 | | 18 | | 23 | | 39 | | 44 | | 59 |
+---+ +----+ +----+ +----+ +----+ +----+
b)(1.5p) What is the maximum height of a (2,4)-tree with n nodes? (Explain your
answer.)
3
6
Hash
a)(1p) Describe separate chaining.
b)(1p) Describe linear probing.
c)(1p) Describe quadratic probing.
d)(1p) Describe double hashing.
e)(1p) The methods described in a)-d) are various methods to solve a problem in hash
table handling. Describe the problem.
7
Skip
Build a skip list for the elements 1, 3, 5, 7, 2, 4, 6, 8 in that order.
The results of the coin tossing are (H=head, T=tail) H, H, T, T, over and over again.
(3p)
4
Download