KOLEJ UNIVERSITI TUNKU ABDUL RAHMAN
FACULTY OF COMPUTING AND INFORMATION TECHNOLOGY
ACADEMIC YEAR 2020/2021
DECEMBER EXAMINATION
COMPUTER SCIENCE BACS2063
DATA STRUCTURES AND ALGORITHMS
FRIDAY, 18 DECEMBER 2020 TIME: 9.00 AM – 12.00 NOON (3 HOURS)
BACHELOR OF COMPUTER SCIENCE (HONOURS) IN SOFTWARE ENGINEERING
BACHELOR OF INFORMATION TECHNOLOGY (HONOURS) IN INTERNET TECHNOLOGY
BACHELOR OF INFORMATION TECHNOLOGY (HONOURS) IN SOFTWARE SYSTEMS
DEVELOPMENT
Instructions to Candidates:
Answer ALL questions in the requested format or template provided.
● This is an open book final online assessment. You MUST answer the assessment questions on
your own without any assistance from other persons.
● You must submit your answers within the following time frame allowed for this online
assessment:
o The deadline for the submission of your answers is half an hour from the end time of this
online assessment.
● Penalty as below WILL BE IMPOSED on students who submit their answers late as follows:
o The final marks of this online assessment will be reduced by 10 marks for answer scripts
that are submitted within 30 minutes after the deadline for the submission of answers for
this online assessment.
o The final marks of this online assessment will be downgraded to zero (0) mark for any
answer scripts that are submitted after one hour from the end time of this online assessment.
● Extenuation Mitigating Circumstance (EMC) encountered, if any, must be submitted to the
Faculty/Branch/Centre within 48 hours after the date of this online assessment. All EMC
applications must be supported with valid reasons and evidence. The UC EMC Guidelines apply.
FOCS Additional Instructions to Candidates:
• Include your FULL NAME, STUDENT ID and PROGRAMME OF STUDY in your
submission of answer.
• Read all the questions carefully and understand what you are being asked to answer.
• Marks are awarded for your own (original) analysis. Therefore, use the time and information to
build well-constructed answers.
This question paper consists of 4 questions on 6 printed pages.
2
BACS2063 DATA STRUCTURES AND ALGORITHMS
STUDENT’S DECLARATION OF ORIGINALITY
By submitting this online assessment, I declare that this submitted work is free from all forms of
plagiarism and for all intents and purposes is my own properly derived work. I understand that I have
to bear the consequences if I fail to do so.
Final Online Assessment Submission
Course Code:
Course Title:
Signature:
Name of Student:
Student ID:
Date:
This question paper consists of 4 questions on 6 printed pages.
3
BACS2063 DATA STRUCTURES AND ALGORITHMS
Question 1
a) Consider that you are developing a software for karaoke centers to host karaoke shows and
playing karaoke songs. Besides displaying the latest new songs, the songs in the system are
grouped by the gender of the singers, the name of the singer, language, region, musical genre,
etc. The system can sort the songs according to the customer’s selection. For example, when a
customer is selecting the songs based on title, the titles are sorted ascendingly; when a customer
is selecting the songs based on singer, the singers are sorted according to their surnames; and so
on. The system allows multiple customers to add songs to their own playlists and then they have
to wait for their turn. For every customer, it will allow each person to sing their chosen songs for
around 10 minutes. After that, the system will select the next user in line to sing. This will repeat
until all songs are played, or the time is up. Any customer can remove any of their selected songs
from the playlist at any time, and they can move the song to the front of the playlist as well. The
system is able to sync the first 10 songs in the playlist to the customers’ smart phones in real time,
so that they know when is their turn even they are outside the karaoke room.
Based on the case study above, analyze how list, stack and queue can be applied in the system.
Explain with relevant examples.
(i) Propose ONE (1) application of list in the karaoke system with an example. (3 marks)
(ii) Propose ONE (1) application of stack in the karaoke system with an example. (3 marks)
(iii) Propose ONE (1) application of queue in the karaoke system with an example. (3 marks)
b) An Abstract Data Type (ADT) named RandomList is used to generate random items in a list.
Refer to the examples below to implement the RandomString Java class that output random
items in a list.
/*Sample main method*/
public class MainProject {
public static void main(String[] args){
String[]str = {"red","orange","blue","yellow","green"};
RandomList randString = new RandomString(str);
randString.createRandomList(3);
System.out.println("randString = " + randString);
}
}
Figure 1.1: Sample main method to generate 3 random Strings
randString = [green,yellow,yellow]
Figure 1.2: The output of the main method
(i) Write the RandomList Java Interface with the relevant abstract method. (3 marks)
This question paper consists of 4 questions on 6 printed pages.
4
BACS2063 DATA STRUCTURES AND ALGORITHMS
Question 1 b) (Continued)
(ii) Complete the RandomString Java Class that implements the RandomList interface
with the following requirements.
Requirement Mark
RandomString Class definition 2
Declaration of class attributes, which include a list (named randList) that 2
stores the required random numbers
Remark: list implementation is not required
A constructor that accepts a String array, which also initializes all the class 3
attributes
The implementation of the abstract class method as given in Question 1b)(i). 6
Remark: you may use any built-in methods or classes to generate the random
numbers.
(13 marks)
[Total: 25 marks]
Question 2
FixedList is an implementation of List ADT, which it only allows the first N items to be inserted to
the list even though more items are attempted to be placed, where N is the size fixed by the users. The
sample below shows the application of a FixedList.
/*Sample main method*/
public class MainProject {
public static void main(String[] args){
List<Integer> fixList = new FixedList(10);
for(int i = 0; i<100; i++){
fixList.insert(i);
}
System.out.println("fixList = " + fixList);
}
}
Figure 2.1: Sample declaration of the FixedList.
fixList = [0,1,2,3,4,5,6,7,8,9]
Figure 2.2: The output of the main method
This question paper consists of 4 questions on 6 printed pages.
5
BACS2063 DATA STRUCTURES AND ALGORITHMS
Question 2 (Continued)
a) One of the implementations of the FixedList is linked list. There are three common types of
linked list, i.e. singly linked list, circular linked list and doubly linked list.
(i) Compare and contrast the strengths and limitation of the THREE (3) types of linked list
if they are going to be applied in the FixedList implementation. (12 marks)
(ii) Select the type of linked list that you think is most suitable to be applied in FixedList
implementation. Justify your answer. (1 mark)
b) Write the FixedList Java Class that implements the List interface with the following
requirements. You must implement it based on the type of linked list that you have selected in
Question 2 a)(ii). You may assume that the List interface and the Node class have been defined.
Requirement Mark
FixedList Class definition 1
Declaration of class attributes 2
A constructor that accepts the size fixed by the user 2
The implementation of the insert method 7
Remark: You may ignore the toString method.
(12 marks)
[Total: 25 marks]
Question 3
a) SpeedMovie is a technology and media services provider. It offers streaming service of a wide
range of popular TV shows, movies, anime, documentaries and more on thousands of internet-
connected devices, such as smart TV, mobile device and personal computer. Their customers can
watch more than one videos at any time. They can also rate the shows that they have watched.
Recently SpeedMovie approached your company to help them to improve the search function of
their system with advanced features.
You are required to propose THREE (3) search functions. The requirements of the proposal of
each search function are given below.
Search Function Details Mark
• Proposed relevant search function with description/example 2
• Proposed implementation of the search function (need to describe the 4
appropriate data structures and search/sort algorithms)
• Evaluate the search time efficiency of your proposed implementation using Big 1
O notation.
Proposal of THREE (3) search functions x3
(21 marks)
b) The following array of numbers are being dequeued to build a binary search tree (BST). Identify
and explain a potential problem of the resulting BST, and then suggest a solution.
Front → 1 2 3 4 5
(4 marks)
[Total: 25 marks]
This question paper consists of 4 questions on 6 printed pages.
6
BACS2063 DATA STRUCTURES AND ALGORITHMS
Question 4
STAR Exam Scheduling System (SESS) is designed to schedule exam papers according to the available
sessions, venues, and the number of students. Each exam paper contains a course code, course title,
exam date, and a list of programme codes of the students who are taking this exam paper. Figure 4.1
shows part of the ExamPaper Java Class, and Figure 4.2 shows one sample data of the ExamPaper
object instance.
public class ExamPaper {
String courseCode;
String courseTitle;
Date examDate;
List<String> programmeCode;
...
}
Figure 4.1: ExamPaper Class
courseCode BACS2063
courseTitle Data Structures and Algorithms
examDate 18 December 2020
programmeCode [RSD2, RIT2, RSF2, REI2, RST2, RIS2, RMM2]
Figure 4.2: Sample ExamPaper instance data
A scheduling problem searches 2,000 exam papers. To increase the efficiency of the search algorithm,
you are considering to use a hash table to retrieve the exam paper object instances, and then sort the
programmeCode.
a) A hash table is an unordered collection of key-value pairs, where each key is unique.
(i) Suggest ONE (1) suitable key for the hash table that allows the SESS to retrieve each
ExamPaper efficiently. (1 mark)
(ii) Based on the key you have identified in Question 4 a) (i), suggest and design an appropriate
hash function to convert the selected key into an integer index. Express your answer in
pseudocode or code. (4 marks)
(iii) One of the challenges of using hash table is collisions. To avoid collisions, there are several
solutions, such as linear probing, quadratic probing, double hashing, and separate chaining.
Explain with examples the THREE (3) considerations that a developer needs to have when
selecting one of these collision resolution methods. Then justify your recommended
method for the SESS. (12 + 2 marks)
b) Figure 4.3 shows a list of programme codes.
Demonstrate the steps of Insertion Sort when sorting the programme codes ascendingly.
You are required to show the contents after each pass.
RSD2 RIT2 RSF2 REI2 RST2 RIS2 RMM2
Figure 4.3: Sample programmeCode data
(6 marks)
[Total: 25 marks]
This question paper consists of 4 questions on 6 printed pages.