0% found this document useful (0 votes)
99 views6 pages

Test#1csc508 20nov2023

The document contains instructions for a data structures exam consisting of 3 questions worth 60 marks total. Question 1 has 10 true/false statements worth 20 marks. Question 2 has parts asking to (i) declare linked lists, (ii) copy patient data between lists, (iii) search and display patient details, and (iv) display patient details, worth 22 marks total. Question 3 has parts asking to (a) draw diagrams showing changes to queues and a stack after a code fragment runs, and (b) show steps to evaluate an infix expression using a stack, worth 18 marks total.

Uploaded by

2023305209
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views6 pages

Test#1csc508 20nov2023

The document contains instructions for a data structures exam consisting of 3 questions worth 60 marks total. Question 1 has 10 true/false statements worth 20 marks. Question 2 has parts asking to (i) declare linked lists, (ii) copy patient data between lists, (iii) search and display patient details, and (iv) display patient details, worth 22 marks total. Question 3 has parts asking to (a) draw diagrams showing changes to queues and a stack after a code fragment runs, and (b) show steps to evaluate an infix expression using a stack, worth 18 marks total.

Uploaded by

2023305209
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CONFIDENTIAL 1 CS/NOV 2023/CSC508

UNIVERSITI TEKNOLOGI MARA


TEST#1

COURSE : DATA STRUCTURES


COURSE CODE : CSC508
EXAMINATION : 20 NOVEMBER 2023
TIME : 2 HOURS (2:00 – 4:00 PM)

INSTRUCTIONS TO CANDIDATES

1. This question paper consists of three (3) questions.

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.

3. Please scan and save your answers as pdf file.

4. No discussion and do not share your answers with other students. Any copying of or
plagiarized answers will be awarded 0 mark.

5. Answer ALL questions in English.

Score Total Marks

QUESTION 1 20

QUESTION 2 22

QUESTION 3 18

TOTAL SCORE 60

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 6 printed pages

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 2 CS/NOV 2023/CSC508

QUESTION 1 (20 marks)

Verify whether the following statements are TRUE or FALSE.

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.

QUESTION 2 (22 MARKS)

Given the following ADT’s:

public class ArrayList


{
// declaration of other methods and data

public ArrayList()
// method definition

public void addFirst(Object elem)


// method definition

public Object get(int index)


// method definition

public Object set(int index, Object elem)


// method definition

public Object remove(int index)


// method definition

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 3 CS/NOV 2023/CSC508

public int indexOf(Object elem)


// method definition

public int size()


// method definition
}

public class LinkedList


{
// declaration of other methods and data

public void insertAtFront(Object elem)


// method definition

public void insertAtBack(Object elem)


// method definition

public Object getFirst()


// method definition

public Object getLast()


// method definition

public Object removeFirst()


// method definition

public Object removeLast()


// method definition

public Object getNext()


// method definition
}

public class CovidPatient


{
private String patName; // patient’s name
private int patIC; // patient’s Identification Card
private String cVariant; // Covid virus variant – SARS-CoV-2, Omicron,
// Alpha, Beta
private String quarantineDate; // date start quarantine
private int cStatus; // Covid status : 1-positif or 0-negative
private float oLevel; // Oksigen level
private int cCategory; // Covid category : 1,2,3,4,5

public CovidPatient(); // default constructor


public CovidPatient(String,int,String,String,int,float,int);
// normal constructor
public String getName(); // accesor method
public int getIC(); // accesor method
public String getcVariant(); // accesor method
public String get quarantineDate(); // accesor method
public int getcStatus(); // accesor method
public float getcLevel(); // getoLevel
public int getcCategory(); // accesor method
public void setCovidPatient (String,int,String,String,int,
float,int); // mutator

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 4 CS/NOV 2023/CSC508

public void setVariant(String); // mutator


public void setStatus(int); // mutator
public void setoLevel(float); // mutator
public void setcCategory(int); // mutator
public void displayInfo(); // display patient’s info

a) Assume 2000 Covid-19 patient data has been inserted in an ArrayList object
named covid19List. Write a Java program segment to:

i. Declare a LinkedList object named OmicronList and EpsilonList.


(2 marks)

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)

QUESTION 3 (18 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:

public class Queue


{
public Queue(); // constructor
public boolean isEmpty();
public void enqueue(Object data); //to add object into a queue
public Object dequeue(); //to delete object from a queue
public Object getFront(); // to return value of first element
public Object getEnd(); // to return value of last element

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 5 CS/NOV 2023/CSC508

public class Stack


{
public Stack(); // constructor
public boolean isEmpty();
public void push(Object data); //to add object into a stack
public Object pop(); //to delete object from a stack
public Object top(); // to return value of top stack
}

myQueue

15 21 10 30 40 54 null

front
back
null
queue1 queue2 null

front back front back

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)

b) Given the following infix expression:

3 + 8 * 8 – 10 * 20 / 5

Show the steps how a compiler would evaluate its value using a stack.
(5 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 6 CS/NOV 2023/CSC508

c) Define method enqueue( ) for a queue implemented using linked list.


(3 marks)

d) Define method pop( ) for a stack implemented using an arraylist.


(3 marks)
©

END OF QUESTION PAPER

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

You might also like