Examination Cover Page
Examination Period: 2021 HE Term 1
Academic Institution: Central Queensland University
Academic Group: Higher Education Division
Academic Career: Postgraduate
Examination Type: 2021 HE Term 1 Standard
Affix Student ID Sticker here
I have read and understood the penalties involved if I do not abide by the rules outlined on the back of this examination
paper.
Student Signature: _______________________________________ Student ID Number:
Unit: Data Structures and Algorithms
Subject Area: COIT
Catalog Number: 20256
Paper Number: 1
Component: ALL Components
Duration 180 minutes Exam Conditions Open Book
Perusal Time 15 minutes
First Contact Jacqueline Jarvis Contact Number XXXXXXXXXX
Second Contact Colin Lemmon Contact Number XXXXXXXXXX
Office Use: Release examination paper via the CQ University Past Exams website two weeks after the DE/SE examination period? Yes
Instructor Authorised/Allowed Materials
Calculator - non-programmable, no text retrieval, silent only
Dictionary - non-electronic, concise, direct translation only (dictionary must not contain any notes or comments).
Student Calculator - Make:____________________ / Model: ____________________
Special Instructions to Students:
Please see instruction sheet on first page of the examination paper.
Examination Office Supplied Materials
1 x Rough Pape
1 x Exam Answer Booklet
Questions Answered Marks Questions Answered Marks
Number of examination answer booklets used:
Number of separate sheets attached (Do not include rough paper):
This examination paper is not to be released to the student at the conclusion of the examination.
Central Queensland University considers improper conduct in examinations to be a serious offence.
Penalties for cheating are exclusion from the University and cancellation with academic penalty from the unit concerned.
Term 1 Standard Examination 2021
Data Structures and Algorithms – COIT20256
Page 1 of 15
INSTRUCTION SHEET
1. Write all answers in the answer booklet provided.
2. Attempt all ten questions.
Term 1 Standard Examination 2021
Data Structures and Algorithms – COIT20256
Page 2 of 15
TOTAL 50 MARKS
Attempt all 10 questions in the answer booklet provided.
Question 1 4 Marks
Describe the purpose of the singleton pattern. Explain what is required to implement the
singleton pattern in Java (and why).
Question 2 4 Marks
A common task in computer-based wargaming is to specify the locations that an aircraft
must fly to when conducting a surveillance mission. These locations are called
waypoints.
(a) What would be a suitable data structure to represent this information? Assume
that a waypoint is specified by x, y and z coordinates. (2 marks)
(b) Explain why you have chosen this data structure over other alternatives.
(2 marks)
Question 3 4 Marks
(a) Explain how hash tables work in terms of hash functions and collisions.
(3 marks)
(b) What would be the consequences if the key for an entry in a hash table was
changed? Explain your answer. (1 mark)
Term 1 Standard Examination 2021
Data Structures and Algorithms – COIT20256
Page 3 of 15
Question 4 6 Marks
The following Queue class uses the generic List class developed in chapter 21 of the
textbook – see Appendix A of this exam for the code from the textbook.
public class Queue
{
private final List< E > q;
see Fig 21.3 for List
public Queue(){
q = new List
("queue");
}
public void enqueue(E object) {
q.insertAtBack(object);
}
public E dequeue(){
return q.removeFromFront();
}
public boolean isEmpty(){
return q.isEmpty();
}
}
public class GenericFIFOQueue {
public static void main(String[] args) {
XXXXXXXXXXQueue queue = new Queue
();
XXXXXXXXXXqueue.enqueue(20);
XXXXXXXXXXqueue.enqueue(10);
XXXXXXXXXXqueue.enqueue(15);
XXXXXXXXXXwhile (!queue.isEmpty()){
XXXXXXXXXXint item = queue.dequeue();
XXXXXXXXXXSystem.out.printf("%d%n", item);
}
}
}
Question 4 continued over the page
Term 1 Standard Examination 2021
Data Structures and Algorithms – COIT20256
Page 4 of 15
Question 4 continued
(a) What is output by this code? Explain your answer. (1 mark)
(b) The data added to the queue is of type int, but the queue is of type Integer. What
conversion happens when the int data is added to the queue (using enqueue)?
(1 mark)
(c) Where else in the code do you see such mixing of types and what happens in that
case? (1 mark)
(d) Suppose that instead of a queue of numbers you want a queue of Customer
ecords (the class diagram for the Customer class is provided below). Rewrite the
main method above to use the Queue class to build a queue with 3 Customer
ecords, then “dequeue” and print the customer records as they come off the
queue. (3 marks)
Term 1 Standard Examination 2021
Data Structures and Algorithms – COIT20256
Page 5 of 15
Question 5 8 Marks
(a) Given the following code, use lambdas and streams to calculate and display
the number of elements in the following a
ay of body mass indexes that are
greater than or equal to 25 (i.e. the total number that are overweight or obese).
(2 marks)
public static void main(String[] args) {
int[] bmis = {10, 20, 35, 27, 16, 29, 33, 21, 22, 25};
use lambdas and streams to work out how many
mis are >= 25 and display the result.
part (a) to complete>
}
Output should be similar to the following:
The number of patients with a body mass greater than or
equal to 25 = 5
(b) The following is the class diagram for the PatientBMI class used in this question.
Question 5 continued over the page
Term 1 Standard Examination 2021
Data Structures and Algorithms – COIT20256
Page 6 of 15
Question 5 continued
Given the code below, use lambdas and streams to complete the main method as
follows:
i. Write a Predicate called unhealthyWeight that returns true if the patient’s bmi is in
the unhealthy weight range (>=25 or < =18) and false if the bmi is in the healthy
weight range. (2 marks)
ii. Make use of the predicate from part (a) to display all the patient records (patient
id and bmi) with body mass indexes that are not in the healthy weight range.
(2 marks)
iii. Use lambdas and streams to calculate and display the summary statistics for the
data (i.e. a count of the data elements, sum of the data elements, minimum,
average and maximum). (2 marks)
public static void main(String[] args) {
PatientBMI[] bmis = {new PatientBMI("P123345", 10),
XXXXXXXXXXnew PatientBMI("P678901", 20),
XXXXXXXXXXnew PatientBMI("P778901", 35),
XXXXXXXXXXnew PatientBMI("P878901", 27),
XXXXXXXXXXnew PatientBMI("P078901", 16),
XXXXXXXXXXnew PatientBMI("P688901", 29),
XXXXXXXXXXnew PatientBMI("P698901", 33),
XXXXXXXXXXnew PatientBMI("P679901", 21),
XXXXXXXXXXnew PatientBMI("P678911", 22),
XXXXXXXXXXnew PatientBMI("P678912", 25)};
XXXXXXXXXXList bmiList = A
ays.asList(bmis);
(i) Write the code for the supplementary predicate
Part (i) To be completed>
(ii) using the predicate (and lambdas and streams),
display the student id and mark for all results in
the supplementary range
Part (ii) To be completed>
(iii) using lambdas and streams calculate and display
the summary statistics (count of patients, total/sum of the data,
average and maximum
Part (iii) To be completed>
}
Question 5 continued over the page
Term 1 Standard Examination 2021
Data Structures and Algorithms – COIT20256
Page 7 of