Tentamen/Exam TDDC32 Design och implementering av programmodul i Java TDDC32 Design and implementation of a software module in Java 2009–08–25 14.00 – 18.00 • No help materials are allowed, except for an English dictionary. • You may answer in Swedish or English. • Total number of credits is 24. Limits: 3: 12p, 4: 16p, 5: 20p. • Jour (person on duty): Jonas Wallgren. 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 city has a number of districts. A district consists a number of blocks. A block consists of number of buildings. A dwelling-house is a building. An office building is a building. A block of flats is a dwelling-house. A villa is a dwelling-house. A block of flats is occupied by a number of families. A villa is occupied by one family. A family consists of several persons. An employee is a person. An office building contains several employees. 2 3 AVL a)(1.5p) Construct the AVL tree from the keys (in the given order) 9 6 7 2 1 11 3 15 4 5. You only need to show the final result. b)(1.5p) Remove 30 from the following AVL tree. Draw the tree transformations step by step. 20 /\ / \ / / \ \ 10 30 /\ /\ / \ / \ 7 14 25 35 / \ / / 3 9 12 22 / 1 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. 3 5 (a,b)-tree a)(2p) Show what happens step by step when you remove the values 10, 44, 20 from the following (2,4)-tree: +----+ | 20 | +----+ / \ / \ +----+ +----+----+----+ | 10 | | 30 | 40 | 50 | +----+ +----+----+----+ | | / | | \ +---+ +----+ +----+ +----+ +----+ +----+ | 3 | | 18 | | 23 | | 39 | | 44 | | 59 | +---+ +----+ +----+ +----+ +----+ +----+ b)(1p) What is a and b in “(a,b)-tree”? How are they related? 6 Hash a)(2p) In a hashtable using linear hashing of size 11 insert: 7, 3, 18, 31, 50, 6, 4, 12, 25, 14 in that given order. Describe where each element is placed and comment/explain why. b)(1p) What is the complexity of introducing one piece of data into the hashtable? In what situations are hashtables preferred to trees? 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, H, T, T, over and over again. (3p) 4