Escolar Documentos
Profissional Documentos
Cultura Documentos
FINAL EXAMINATION
INSTRUCTIONS TO CANDIDATES:
3. Do not bring any material into the examination hall unless permission is given by
the invigilator.
IC NO. : _______________________________
ID. NO. : _______________________________
LECTURER : JUNAIDAH SAID
SECTION : 2/4
QUESTION 1
6 2 4 7 9 3 8 1 5 6 Logical representation
i) What will happen if the original number list is inserted with 2 more
numbers?
ii) Given two numbers are 21 and 34. Draw the new logical representation
of list number after these two numbers as been inserted in the list.
(4 marks)
import java.util.*;
import javax.swing.*;
CONTINUE
CONFIDENTIAL 3 NOV2008/SET A/COS329
a. What is the output of the above application if the inputs for the program are
27, 82, 73, 26, 19 and 21.
(4 marks)
(4 marks)
ii. Count and display all positive and negative numbers in intList.
(5 marks)
83 79 92 12 78 52 38 51
Total: ( 30 marks)
TURN OVER
CONFIDENTIAL 4 NOV2008/SET A/COS329
QUESTION 2
a. State the differences between single linked list and doubly linked list.
(4 marks)
i. Write Java codes for a method getAverage() from Athlete class above
which will return average distance for each athlete
(4 marks)
CONTINUE
CONFIDENTIAL 5 NOV2008/SET A/COS329
Input 7 athletes that participate in the long jump event in Olympic Games
into the LinkedList.
(6 marks)
Find and display the winner's information of that event. One athlete will have
three attempts. The winner will be the one with the longest jump among all the
athletes.
(6 marks)
Display the average distance of all the jumps obtained by the athletes.
(5 marks)
(Total: 21 marks)
QUESTION 3
d. What happens during execution of the above method for power(2, 3) if the
statement in //LINE 5 is changed to:
(2 marks)
(Total: 13 marks)
TURN OVER
CONFIDENTIAL 6 NOV2008/SET A/COS329
QUESTION 4
a. State TWO (2) differences between a stack and a queue by using (draw) a model
of each structure.
(6 marks)
i) A+B*(C-D)/(E-F)
(5 marks)
(Total: 21 marks)
QUESTION 5
a. Discuss TWO (2) advantages of storing data in a Binary Search Tree compared
to storing in an unsorted LinkedLlist.
(4 marks)
B C
D F
E
G
H
I
CONTINUE
CONFIDENTIAL 7 NOV2008/SET A/COS329
iii. What is the output if the elements are written out using the pre-order traversal of
the above tree?
(2 marks)
e.
i. Build an expression tree for the following postfix expression:
cd*ab+-db/%
(5 marks)
f. Construct a binary search tree (BST) from the following set of data according the
order given:
45 27 31 70 65 84 12 55 38 47
(5 marks)
(Total: 28 marks)
END OF PAPER
TURN OVER