Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

FACULTY OF SCIENCE

ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING

MODULE CSC03A3/CSC3A10
COMPUTER SCIENCE 3A

CAMPUS AUCKLAND PARK CAMPUS (APK)

ASSESSMENT (2,4) TREE EXAMPLES MEMO

DATE: 2020-05-20 SESSION: Practice

ASSESOR(S): PROF D.T. VAN DER HAAR


MR R. MALULEKA

DURATION: 50 MINUTES MARKS: 30

Please read the following instructions carefully:

1. Answer all the questions

2. Write cleanly and legibly.

3. You may use a non-programmable calculator to answer the questions.

4. This paper consists of 6 pages.


Computer Science 3A (2,4) Tree Examples 2020-05-20

QUESTION 1
Consider the following (2,4) tree provided below. Draw the (2,4) tree state
after each of the following operations. If the tree is rebalanced draw the
state before and after it being balanced.

1. Insert nodes that contain the following keys: (inserted one-by-one, in


the given order)
18, 13, 41, 1, 17, 22, 41
2. Delete nodes that contain the following keys: (removed one-by-one,
in the given order)
6, 1, 31, 17, 22

31

6 28 39 40

Solution:
Insert 18

[1 mark]:
31

6 18 28 39 40
Insert 13

<<Rebalancing>> [2 marks]:

18 31

6 13 28 39 40
[1 mark]:
18 31

6 13 28 39 40
Insert 41

[1 mark]:

Page 1 of 6
Computer Science 3A (2,4) Tree Examples 2020-05-20

18 31

6 13 28 39 40 41
Insert 1

[1 mark]:
18 31

1 6 13 28 39 40 41
Insert 17

<<Rebalancing>> [2 marks]:

13 18 31

16 17 28 39 40 41
[1 mark]:
13 18 31

16 17 28 39 40 41
Insert 22

[1 mark]:
13 18 31

16 17 22 28 39 40 41
Insert 41

Remove 6

[1 mark]:
13 18 31

1 17 22 28 39 40 41
Remove 1

13 [1 mark]:

Page 2 of 6
Computer Science 3A (2,4) Tree Examples 2020-05-20

18 31

13 17 22 28 39 40 41
Remove 31

[1 mark]:
18 28

13 17 22 39 40 41
Remove 17

[1 mark]:
18 28

13 22 39 40 41
Remove 22

[1 mark]:
18 39

13 28 40 41
Total: 15 marks

Total: 15

QUESTION 2
Consider the following (2,4) tree provided below. Draw the (2,4) tree state
after each of the following operations. If the tree is rebalanced draw the
state before and after it being balanced.

1. Insert nodes that contain the following keys: (inserted one-by-one, in


the given order)
35, 29, 2, 34, 8, 19, 49
2. Delete nodes that contain the following keys: (removed one-by-one,
in the given order)
5, 34, 49, 35, 29

Page 3 of 6
Computer Science 3A (2,4) Tree Examples 2020-05-20

18

05 29 48

Solution:
Insert 35

[1 mark]:
18

05 29 35 48
Insert 29

Insert 2

[1 mark]:
18

025 29 35 48
Insert 34

<<Rebalancing>> [2 marks]:

18 35

025 29 34 48
[1 mark]:
18 35

025 29 34 48
Insert 8

<<Rebalancing>> [2 marks]:

5 18 35

02 8 29 34 48
[1 mark]:

Page 4 of 6
Computer Science 3A (2,4) Tree Examples 2020-05-20

5 18 35

02 8 29 34 48

Insert 19

[1 mark]:
5 18 35

02 8 19 29 34 48

Insert 49

[1 mark]:
5 18 35

02 8 19 29 34 48 49

Remove 5

[1 mark]:
2 18 35

0 8 19 29 34 48 49

Remove 34

[1 mark]:
2 18 35

0 8 19 29 48 49

Remove 49

[1 mark]:
2 18 35

0 8 19 29 48

Remove 35

[1 mark]:

Page 5 of 6
Computer Science 3A (2,4) Tree Examples 2020-05-20

2 18 29

0 8 19 48
Remove 29

[1 mark]:
2 18

0 8 19 48
Total: 15 marks

Total: 15

— End of paper —

Page 6 of 6

You might also like