Some solutions to TDDC32 2013-03-15

advertisement
Some solutions to TDDC32
Design and implementation of a software module in Java
2013-03-15
The following are solution sketches to the assignments on the exam. The solutions given here are
only meant as a guide and are often not sufficient as answers on the exam.
1. (a) Analysis — investigation in order to understand the problem, vocabulary, business rules,
and so on.
(b) Design — a logical (pre-software) solution that fulfills the requirements.
2. The following class diagram is one of many possible interpretations of the question:
1
3. (a)
20
20
5
10
30
15
25
35
5
30
15
25
35
10
(b) If a or b exists in the AVL tree the answer is true. Otherwise? Searching for a +
1, a + 2, . . . , b − 1 is very slow. (Depends on the key values, not the number of nodes in
the tree.) If searches for a and b terminate in a0 and b0 (a0 6= b0 ), there exists specific
weights between a and b: the ancestor of a0 and b0 is one of them. If both failed searches
terminate in the same leaf the answer is false. The time complexity becomes O(log n).
4. Se the course book chapter 9.4.
5. Yes, insert all elements into a splay tree and perform an inorder traversal of the tree. This
takes time O(n log n) in the worst case, since every insertion takes amortized time O(log n)
and we perform n insertions.
6. (a)
(b)
0
G
1
D
2
B
3
F
4
E
5
A
6
C
I results from inserting the keys in order F D B G E C A.
II cannot result. The first key inserted will end up in the table entry corresponding
to its hash values. But no key has this property.
III cannot result. Both B and G end up in the table entry corresponding to their hash
values, so we can assume they were inserted first and second. So, the third key
inserted will also end up in the table entry corresponding to its hash value . But
no keys (beside B and G) have this property.
7. (a)
12
5
3
6
8
7
10
9
15
11
14
17
(b) Using terminology from the course book, we get:
12
underflow
5
3
8
6
10
9
5
15
11
12
fusion
3
14
2
8
6
10
9
15
11
14
5
8
10
12
transfer
5
10
3
3
6
9
11
14 15
3
8
6
12
9
11
14 15
Download