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

2011–03–19

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, tel. 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 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) 7, 6, 5, 4, 3, 2, 1.

You only need to show the result after completing the insertion of 2 and the final tree.

b)(1.5p) Remove 20 from the following AVL tree. Draw the tree transformations step by step.

20

/\

/

/

/ \

\

\

1

/

10

/\

/ \

30

/\

/ \

7 14 25 35

/ \ / /

3 9 12 22

4 Splay

Both of these subproblems use the splay tree given in a) as its starting-point.

Solving one subproblem doesn’t influence the other one.

a)(1.5p) Add the value 54 to the following splay tree. Show the transformations step by step.

20

/ \

10 30

/\ \

7 14 35

\

39

\

46

/\

41 55 b)(1.5p) Remove the value 55 from the splay tree above. Show the transformations step by step.

3

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.)

6 Hash

a)(1.5p) In a hashtable using linear hashing of size 11 insert: 56 22 78 67 15 41 37 87 25 33, in that given order.

Describe where each element is placed and comment/explain why.

b)(1.5p) What is the complexity of introducing one piece of data into the hashtable?

In what situations are hashtables preferred to trees?

7 Skip

(3p) 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.

4

Download