Test#1csc508 20nov2023
Test#1csc508 20nov2023
INSTRUCTIONS TO CANDIDATES
2. Answer ALL questions in your answer sheet. Start each answer on a new page. Write your
name, id and group on the answer sheet.
4. No discussion and do not share your answers with other students. Any copying of or
plagiarized answers will be awarded 0 mark.
QUESTION 1 20
QUESTION 2 22
QUESTION 3 18
TOTAL SCORE 60
a) The postfix notation for arithmetic expressions places binary operators ahead of
both of their operands.
b) Deletion of an element in the front of an ArrayList object takes shorter time than the
deletion of an element in the front of a LinkedList object.
c) Insertion of a new element and deletion of an element and can be done at the top
of stack only.
d) head.next == null shows that the linked list is full.
e) Evaluation of mathematical expression: 10 2 8 * + 3 - is equivalent to 23.
f) The queue data structure concept is LIFO, and stack is FIFO.
g) A general case in recursive method must eventually reduce to a base case.
h) Each node in a doubly linked list is refers to both its predecessor and successor.
i) In recursive algorithm, the base case determines the exit condition.
j) Insertion into a Queue is always done at the front of the queue.
public ArrayList()
// method definition
a) Assume 2000 Covid-19 patient data has been inserted in an ArrayList object
named covid19List. Write a Java program segment to:
ii. copy all the patient data who has contracted virus variant Omicron and Epsilon
from covid19List to OmicronList and EpsilonList, respectively.
(4 marks)
iii. Search and display all details of patients who are in category 4 and 5, and has
dropped their oxygen level less than 90 from the array list covid19List.
(6 marks)
iv. display the details of the patients in the LinkedList named EpsilonList, for
all patients who already confirmed negative and can be discharged from the
hospital.
(6 marks)
b) Compare the performance of inserting an element in the array list and inserting an
element in the linked list. Determine which one is faster. Briefly explain your reason.
(4 marks)
a) Given the following Queue and Stack class and the diagram that shows myQueue,
queue1, queue2 and mystack which are objects of Queue and Stack class
respectively:
myQueue
15 21 10 30 40 54 null
front
back
null
queue1 queue2 null
mystack
stackTop null
Draw the diagram of myQueue, queue1, queue2 and mystack after execution of the
following code fragment.
while (!myQueue.isEmpty())
{
Integer num = (Integer)myQueue.dequeue();
int nombor = num.intValue();
queue1.enqueue(nombor);
if (nombor % 3 == 0)
queue2.enqueue(nombor);
else
mystack.push(nombor);
}
(7 marks)
3 + 8 * 8 – 10 * 20 / 5
Show the steps how a compiler would evaluate its value using a stack.
(5 marks)