BACS2063 2020-Oct Final Exam Question Paper
BACS2063 2020-Oct Final Exam Question Paper
SEPTEMBER/OCTOBER EXAMINATION
Instructions to Candidates:
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.
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.
Question 1
a) Algorithm analysis focuses on the growth rate of the running time as a function of the input size n. The
Big-O time efficiency.
(i)
elapsed between the start and end time of running the algorithm. (6 marks)
(ii) How does the Big-O Notation resolve these limitations from Question 1 a) (i)? Justify your
answer with an example of code segment (in your code example, indicate how do you derive
the Big-O). (5 + 5 marks)
(iii) Consider two programs A and B that have the following Big-O time efficiency:
A: O(n)
B: O(n2)
If each program requires 10 seconds to solve a problem of size 1000, estimate the time
required by each program to solve a problem of size 2000. (4 marks)
b) When is it suitable to use a Queue ADT? Explain your answer by giving an example of a system or an
application that would use a Queue ADT. Your answer should include what is the object in the queue
and how this ADT is used. (10 marks)
c) Analyze TWO (2) benefits of using abstraction in the data structures. Justify your answer with relevant
examples. (8 marks)
d) Consider the program output in Figure 1(a). The output shows a triangle shape where the line number
.
(i) This problem can be solved iteratively, as shown in Figure 1(b). For the output in Figure 1(a),
the shape is produced by passing n=10 to the method drawPattern. Write a recursive solution
to the code segment in Figure 1(b). Your answer should be written in one or more methods.
You do not need to write the code for the driver program. (8 marks)
(ii) Compare the iterative solution in Figure 1(b) with your recursive solution in Question 1 d)
(i). Which is a better solution? Briefly explain your reason. (4 marks)
Question 2
a) The Penang State Public Library would like to implement a search function to their existing library
system.
Books are being represented as objects in the library system.
Figure 2 below shows the relationship between the Book class and the BookCopy class.
Book BookCopy
- ISBN: String - bookID: String
- title: String - book: Book
- authors: String[] - dateReceived: Date
Figure 2: Part of the Analysis Class Diagram for the Penang State Public Library System
}
}
Figure 3: Code Snippet of the Book Class and BookCopy Class
The Search function allows the user to enter a word (which should be part of the book title) to search for
a book from a database. The returned records (books which have the title containing the searched word)
would be stored in a suitable variable (X) of a particular Collection Abstract Data Type (ADT). The
variable X should be able to be sorted by the title in ascending order (A-Z). If the user clicks on a particular
book title from the search results, the system must be able to access that particular book from variable X
and display the details of the book.
You are being assigned to develop this search function for the above requirements.
Select a suitable Abstract Data Type (ADT) to store the search object of book. Justify why your ADT is
suitable for this purpose. (10 marks)
Question 2 (Continued)
b) The code segment given in Figure 4 is the implementation of a sorting algorithm that sorts an array of
String in ascending order.
Based on the code segment given in Figure 4, answer the following questions:
(ii) The usual number of results returned from the search in Question 2 a) is between 1 to 20 books.
Based on the algorithm you had given in Question 2 b) (i), is this sorting algorithm suitable to
be used to sort the book search results in Question 2 a)? Why?
(6 marks)
(iii) Suppose the sorting algorithm shown in Figure 4 is used to sort the book titles returned in the
search results in Question 2 a). Some sample data of book records is shown in Table 1.
Illustrate how the algorithm in Figure 4 sorts the book objects based on the title. Show your
answers in Figure 5 and explain the changes after each pass is performed.
(12 marks)
0 1 2 3
The Simplicity
Original Clutter-Less
of Less
After Pass 1
Figure 5
Question 2 (Continued)
c) Based on the binary search tree from Figure 6, answer the following questions:
E J
B F H M
K P
A C
O R
(i) Show the results of the inorder and postorder traversals on the binary search tree in Figure 6.
(6 marks)
d) You are intending to store the details of 75 students of the Vegan Society into a hash table with table
size as 83. Design an appropriate hash function using the Student ID (sample data given below) as
input. Express your answer in coding or algorithm. (8 marks)
20PMD1250 20PMD1251 20PMD1252 20PMD1325
[Total: 50 marks]