The Institute of Technology at Link¨ oping University June 7, 2013

advertisement
The Institute of Technology at Linköping University
Department of Computer and Information Science
Tommy Färnqvist
June 7, 2013
TDDC32
Design and implementation of a software module in Java
Tentamen/Exam (TEN1) 2013-06-07, 8–12 (R41)
Examiner:
Questions:
Max points:
Assistance:
Tommy Färnqvist
Tommy Färnqvist (phone 070 4547668).
26 points (grade 5 = 21p, 4 = 17p, 3 = 13p)
Besides an English dictionary, no other means of assistance are allowed.
Please observe the following
• The solutions can be written in English or Swedish, as you prefer.
• Solutions to different problems should be placed one-sided on separate page(s). Do not write
two solutions on the same sheet of paper.
• Sort the solutions before handing them in.
• JUSTIFY YOUR ANSWERS PROPERLY: missing or insufficient explanations will result
in reduction of points. Even incorrect answers may result in points if properly motivated.
• If a problem allows different solutions, e.g. algorithms of different complexity, only optimal
solutions give maximal number of points.
• MAKE SURE THAT YOUR SOLUTIONS/ANSWERS ARE READABLE.
• Leave space for comments.
Good luck!
1
1. OOAD
When applying the Unified Process methodology to a software project, the Construction
phase builds the system in a series of iterations. What is meant by this?
(2 p)
2. UML
Describe the following situation using a class diagram. Show concepts, associations, and
attributes.
(4 p)
A vehicle may either be a land vehicle or a marine vehicle. Amphibious craft are both land
and marine vehicles. Every vehicle has one or more engines, where an engine may either use
diesel or petrol as fuel. A land vehicle may use petrol or diesel as fuel, while a marine vehicle
must use diesel (for fire safety). An engine has a maximum power measured in watts and a
current revolution speed, measured in revolutions per second.
Every marine vehicle has one or more propellors, while a land vehicle has two (2) or more
wheels. One engine powers one or more propellors and one or more wheels.
Trucks, motorbikes, cars, and locomotives are special types of land vehicle.
A motorbike has two (2) or three (3) wheels. A truck and a car have at least four (4) wheels,
while a locomotive has at least six (6) wheels. On a car and a truck, one engine powers two
(2) or more wheels. On a locomotive, one engine powers four (4) or more wheels. One wheel
is always connected to at most one other wheel on any land vehicle.
A car has a current gear value, which is an integer between 1 and 5. A car also has a speed
function which given a current gear value and a current revolution speed (of an engine),
returns the velocity (in km per second) of the car.
3. AVL trees and (a, b)-trees
(4 p)
(a) Consider an AVL tree. Initially suppose the tree contains only a root node with the
key 1. First insert these keys in the given order: 2, 3, 4, 5. Next remove these keys in
the given order: 1, 2, 3. Redraw the tree after each operation is complete.
(2)
(b) Consider a (2, 4)-tree. Initially suppose the tree contains only a root node with key 1.
First insert these keys in the given order: 2, 3, 4, 5. Next remove these keys in the given
order: 1, 2, 3. Redraw the tree after each operation is complete.
(2)
4. Hashing
We use an array with indices from 0 to 10 to implement a hash table of length 11 using
h1 (k) = k mod 11 as hash function. Show the contents of the initially empty array after
inserting these keys in the order given: 9, 7, 20, 18, 31, 33, 29 when the following technique
is used:
(4 p)
(a) separate chaining.
(1)
(b) open addressing with linear probing.
(1)
(c) open addressing with quadratic probing.
(1)
(d) open addressing with double hashing, where h2 (k) = (k mod 7)+1 is used as secondary
hash function.
(1)
5. Splay trees
What does the splay tree below look like after:
(a) last() (the operation that finds the maximum item)
2
(4 p)
(1)
(b) insert(4.5)
(1)
(c) find(10)
(1)
(d) remove(9)
(1)
For each exercise, start from the original tree, not the tree resulting from the previous
operation.
3
/ \
1
5
/\
/\
0 2 4 11
/ \
7
12
/ \
6
9
/ \
8
10
6. ADT Dictionary
Describe an efficient dictionary structure for storing n entries that have an associated set of
r < n keys that come from a total order. That is, the set of keys is smaller than the number of
entries. Your structure should perform operation getAll() in O(log(r) + s) expected time,
where s is the number of entries returned, operation entrySet() in O(n) time, and the
remaining operations of the dictionary ADT in O(log(r)) expected time.
(3 p)
7. ADT Map
Suppose an application uses only three operations, insert(), find(), and remove().
(3 p)
(a) Under what circumstances would you use a splay tree instead of a hash table?
(1)
(b) Under what circumstances would you use a (2, 4)-tree instead of a splay tree?
(1)
(c) Under what circumstances would you use an unordered array instead of a (2, 4)-tree?
(1)
8. Skip lists
Show the result of performing the operations remove(31), insert(48), insert(24), and
remove(17) on the initial skip list given below. Assume that for the first insert two heads
are flipped before a tails and for the second insertion three heads are flipped before a tails.
3
(2 p)
Download