The Institute of Technology at Linköping University Department of Computer and Information Science Tommy Färnqvist March 15, 2013 TDDC32 Design and implementation of a software module in Java Tentamen/Exam (TEN1) 2013-03-15, 14–18 (U1, U3, U4, T2) Examiner: Questions: Max points: Assistance: Tommy Färnqvist Tommy Färnqvist (phone 070 4547668). 24 points (grade 5 = 19p, 4 = 15p, 3 = 12p) 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 In the approach to “analysis” and “design” that has been studied in this course, briefly compare and contrast these two terms. What is “analysis” about? What is “design” about? (2 p) 2. UML In this problem, the domain is an information system for a video rental store. Simplifying assumptions and details: (5 p) • It is a stand-alone store, not part of a larger organization. • Rents only videos, not computer games or other items. • A “video” can be any medium: tape, DVD, and so on. • The rental charge may vary by medium. For example, DVD rentals are more expensive than tapes. • The store does not sell anything, For example, there are no sales of videos or food. • All transactions are rentals. • The input medium by which membership and video rentals are captured is not important. • Cash-only payments. • On completion of rental, the customer receives a transaction report with “typical” information on — use your judgement. • Each renter has a separate membership. With this information you might identify the following use cases and related actors: 2 Furthermore, here is an excerpt from the Rent Videos use case in expanded, essential, conversational style: Bounded by the provided Rent Videos use case, create a conceptual model and illustrate it in UML notation (i.e., draw a class diagram). Show concepts, associations, and attributes. 3. AVL trees (4 p) (a) Consider the following AVL tree. Insert the key 10 into the tree and rebalance it, if necessary. (1) 20 5 30 15 25 35 (b) A group of biologists are storing information about DNA structures in an AVL tree using the specific weight of structures (an integer) as keys. The biologists constantly need to answer questions of the type “Are there any structures in the tree with specific weight between a and b (inclusive)?”, and they want answers fast. (3) Describe an algorithm that, given integers a and b, returns true if there is a key x in the tree, such that a ≤ x ≤ b, and false if no such key exists in the tree. What is the time complexity of your algorithm? 4. Skip lists Describe, in a few sentences, the idea behind the implementation of the data structure skip list. Also draw an illustrative picture. What is the expected search time in a skip list containing n elements? 3 (3 p) 5. Splay trees Is it possible to use a splay tree to sort n comparable elements in O(n log n) worst-case time? Why/why not? (3 p) 6. Hashing We use an array with indices from 0 to 6 to implement an openly addressed hash table of length 7 using the following table of hash values: (4 p) hash value 5 2 5 1 4 1 3 key A B C D E F G Assume that linear probing is used to handle collisions. (a) Illustrate the state of the array after the keys have been inserted in alphabetical order: A, B, C, D, E, F, G. (2) (b) Suppose that the keys are inserted in some order into an, initially empty, instance of the hash table above. Which of the following could be the contents of the linear-probing array? (2) I. 0 A 1 F 2 D 3 B 4 G 5 E 6 C II. 0 F 1 A 2 D 3 B 4 G 5 E 6 C III. 0 C 1 A 2 B 3 G 4 F 5 E 6 D 7. (a, b)-trees Let T be the (2, 4)-tree below, which stores records containing integer keys. Draw all intermediate steps (split, fusion, transfer) and the tree resulting from performing the following operations on T : (3 p) (a) Inserting a record with key 7 into T . (1) (b) Removing a record with key 17 from T . (2) Note that the operations are to be performed independently, i.e. on separate copies of T . No points are awarded for part (b) if the removal is performed on the tree resulting from the insertion in part (a) (or vice versa). 12 5 3 8 6 10 9 15 11 4 14 17