Exam Paper Fa1 2022s1 Memo

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

Student Number

Surname & Initials

YEAR: 2022
SEMESTER: 1
ASSESSMENT: FA 1 MEMO

SUBJECT NAME: DATA STRUCTURES AND ALGORITHMS V

SUBJECT CODE: DTD117V


QUALIFICATION(S): ADRS20 ADVANCED DIPLOMA IN COMPUTER SCIENCE

PAPER DESCRIPTION: COMPUTER DURATION: 4 HOURS PAPER: ONLY


BASED

SPECIAL REQUIREMENTS
 NONE
 NON-PROGRAMMABLE POCKET CALCULATOR
 SCIENTIFIC CALCULATOR
 COMPUTER ANSWER SHEET
 GRAPH PAPER
 DRAWING INSTRUMENTS

OTHER: COMPUTER
ANSWER BOOK

INSTRUCTIONS TO CANDIDATES: ANSWER ALL QUESTIONS

THIS TEST IS TO BE ANSWERED ON PC AND ON ANSWER BOOK


WHEN YOU ARE DONE. GIVE YOUR ANSWER SCRIPT BACK TO THE
INVIGILATOR AND SUBMIT YOUR FILE.

TOTAL NUMBER OF PAGES INCLUDING COVER PAGE: 7

TOTAL NUMBER OF ANNEXURES: 0

EXAMINER: Dr N Baloyi, Prof S Mokwena & Mr N Dlamini FULL MARKS: 100

MODERATOR: Ms Mpho Nkosi TOTAL MARKS: 100


STUDENT TOTAL: ___
STUDENT %: ___

1 DTD117V – FA1 MEMO (2022S1)


Preparation

Theory
a. Use the Word to answer the questions for section A and convert it to PDF before submission.
b. Show all steps where applicable.
c. Write legibly

Practical
a. Use Java to create the programs required in section B
b. Write your code legibly and provide comments
c. To evidence your output, capture the output of all the various functionality requirements into a word
document (correctly numbered) and save it as PDF at the end.
d. You are then required to upload the PDF output file and the associated code (.java files) into Britespace.

2 DTD117V – FA1 MEMO (2022S1)


Section A – Theory [50]

Question 1 [20]

1.1 Insert the values 5, 9, 7, 3, 8, 12, 6, 4, and 20 into a binary search three drawing a different tree for each
stage of the insertion. Only show that final tree. You may scribble on paper but need to draw the final tree
digitally. (10)

Answer:

[allocate 10 marks for the correct answer (i). No partial marks applicable]

1.2 Explain how a deletion is performed in an AVL tree. (5)

Deleting any node requires one to recalculate the balance factors to determine if the tree is still balanced
after the deletion. If not balanced, one needs to balance it out. When deleting a node with children,
replace that node with its inorder predecessor (largest element from the left subtree) or inorder successor
(smallest element from the right subtree).

[allocate up to 5 marks for correct answer. Answers may slightly differ]

1.3 What is the formula to calculate the balance factor for AVL trees? (2)

Answer: Balance factor = Height (left subtree) – Height (right subtree)

[allocate 2 marks for correct answer.]

1.4 What is the acceptable balance factor for AVL trees (2)
3 DTD117V – FA1 MEMO (2022S1)
Answer: between -1 and 1, i.e. -1, 0 or 1.

[allocate up to 2 marks for correct answer.]

1.5 What colour should the root node of a Red-black tree be? (1)

Answer: Black.

[allocate 1 mark for correct answer.]

Question 2 [30]

2.1 Distinguish between linear and non-linear data structures and provide at least one example of each.
(6)

Answer:
Linear data structures: When all of elements are arranged in the linear order, with each element has the
successors and predecessors except the first and last element. Queue.
Non-linear data structures: A non-sequential data structure where each item or element is connected with
two or more other items in a non-linear arrangement. AVL tree.

[allocate up to 6 marks for correct answers. Answers may differ]

2.2 List and explain any two types of complexity. (4)

Answer:
Time Complexity: Running time of the program as a function of the size of input
Space Complexity: Amount of computer memory required

[allocate up to 4 marks for correct answers. Answers may differ]

2.3 List and distinguish between three types of linked list data structures. (9)

Answer:
Singly Linked List - made up of two field node with the last element pointer field being NULL and a pointer
to first element (start). Navigation/traversal is one way.

Doubly Linked List - made up of three field node with pointers in both directions. The last element pointer
field is NULL, it has a pointer to first element (start) and the pointer to prev for first element is NULL.
Navigation/traversal is bi-directional

Circularly Linked List - made up of two field node similar to a singly linked list. It has a pointer to first
element (start) and simulates circular traversal. The last element pointer field is points to first element.

4 DTD117V – FA1 MEMO (2022S1)


[allocate up to 9 marks (3 per list type) for correct answers. Answers may differ and marks could be given for
drawings where explanations are not detailed]

2.4 Discuss a double ended queue and its variations. You may also utilize diagrams to clarify certain points.
(6)

Answer:
In a double ended queue, insertion and deletion done at both ends. It can be used as a palindrome checker
if one is removing elements from both ends at the same time. It can be used both as Stack and Queue but
does not follow FIFO principle.

There are two types of the double ended queue data structure. The first is "input restricted" in which
insertion happens only on one end while deletions can happen on both ends.

The second type is "output restricted" in which insertion happens on both ends but deletion happens only
on one end.

[allocate up to 7 marks for correct answers. Answers may differ]

2.5 Distinguish between depth first search and breadth first search. (5)

Answer:
Depth-First Search (DFS) Algorithm: It starts with the root node and first visits all nodes of one branch as
deep as possible of the chosen Node and before backtracking, it visits all other branches in a similar
fashion. There are three sub-types under Depth-First Search, namely, inoder, preorder and postorder
traversals.

Breadth-First Search (BFS) Algorithm: It also starts from the root node and visits all nodes of current depth
before moving to the next depth in the tree.

[allocate up to 5 marks for correct answers. Answers may differ]

5 DTD117V – FA1 MEMO (2022S1)


Section B – Practical/Programming [50]

Question 3 [30]

3.1 Develop a simple java program to demonstrate the use of the min heap. Construct a min heap using the
following elements or insert the following elements into a min heap: the elements: 10, 20, 30, 1, 2, 3, 4, 11,
21, 41. Display the tree or elements of the tree after its construction. (20)

Answer

2 3

11 10 30 4

20 21 41

OR

The values should be in the following order: 1, 2, 3, 11, 10, 30, 4, 20, 21 and 41.

[allocate up to 20 marks for correct answer. No partial marks applicable]

3.2 Display the array index of the node with value 11? (2)

Answer: index 3

[Allocate 2 marks for correct answer]

3.3 Delete a value from the min heap and display the elements of the heap. (8)

Answer: 2, 10, 3, 11, 41, 30, 4, 20 and 21

[Allocate 8 marks for correct answer]

6 DTD117V – FA1 MEMO (2022S1)


Question 4 [20]

Develop a program that uses a queue data structure to perform the functions below. You should use the Java
built-in package to develop the program. Only if you do not know how to use the built-in package should you
develop the logic behind the different functions. Make sure that your program is intuitive for a user friendly. You
might need more than one queue or data structure to perform some of the operations.

4.1 Create and initialise a queue data structure named TeamsQueue with the following values: Sundowns,
RoyalAM, City, Pirates, Chiefs, Stellenbosch, Amazulu, Supersport, Arrows and Sekhukhune using the
appropriate function. Each initialisation operation should display a message such as “value XX added into
queue TeamsQueue”. (7)

[allocate up to 7 marks for correctly creating, initializing the queue and display appropriate message]

4.2 Display the all the elements of the queue. (1)

Answer: Sundowns, RoyalAM, City, Pirates, Chiefs, Stellenbosch, Amazulu, Supersport, Arrows,
Sekhukhune

[allocate 1 mark for correct display from queue]

4.3 Add the value Galants to the queue and display the resultant output (values) of the queue. (2)

Answer: Sundowns, RoyalAM, City, Pirates, Chiefs, Stellenbosch, Amazulu, Supersport, Arrows,
Sekhukhune, Galants

[allocate 2 marks for successfully adding 13 to the queue]

4.4 Remove the first element in the queue and display the resultant output (values) of the queue. (2)

Answer: RoyalAM, City, Pirates, Chiefs, Stellenbosch, Amazulu, Supersport, Arrows, Sekhukhune, Galants

[allocate 2 marks for successfully deleting 10 from the queue]

4.5 Display the size of TeamsQueue. (2)

Answer: Size = 10

[allocate 1 mark for correct display from queue]

4.6 Update the values City to Cape Town City and display the resultant output (values) of the queue. (3)

Answer: RoyalAM, Cape Town City, Pirates, Chiefs, Stellenbosch, Amazulu, Supersport, Arrows,
Sekhukhune, Galants

[allocate 2 marks for the update and 1 mark the correct display]

4.7 Update the values RoyalAM to Royal AM and display the resultant output (values) of the queue. (3)

Answer: Royal AM, Cape Town City, Pirates, Chiefs, Stellenbosch, Amazulu, Supersport, Arrows,
Sekhukhune, Galants

[allocate 2 marks for the update and 1 mark the correct display]

The End

7 DTD117V – FA1 MEMO (2022S1)

You might also like