Professional Documents
Culture Documents
1. Explain the purpose and give one example for each of the following techniques:
[Solution]
(a) Data validation checks if the input data is reasonable. Example: length check,
range check, presence check, format check, check digit
(b) Data verification checks if the input data is what the user intends to enter.
OR Data verification ensures the input data matches the original resource.
Example: enter password twice, proofread before submitting forms
2. (a) Describe the main function of each of the layers in order in the TCP/IP model.
[3]
(b) Describe how data is transmitted in a packet switching network. Give two
advantages of packet switching over circuit switching network. [4]
[Solution]
(a)
Application: high-level functionality to end users.
Transport: functionality to transmit messages between any two programs.
Network: functionality to determine a route between any two devices.
Data Link: functionality to transmit packets from one device to an adjacent device
in the same network.
Physical: functionality to transmit individual bits through a transmission medium.
(b) Data is separated into packets and each packet independently finds the best route
to the receiver.
Advantages:
Different packets may travel in different route and thus more efficient, saves
bandwidth and avoids congestion. It is also more secured since it became much harder
to attack all the routes instead of one route in circuit switching network.
(c) Switch works at Data Link layer; router works at Network layer
Switch maintains a MAC address table; router maintains a routing table for IP address
3. Vaccination centres are set up in the community to fight against the pandemic.
(a) At each vaccination centre, the Admin staff are able to retrieve and update the
vaccination status directly from Ministry of Health’s centralized database.
(ii) Give one advantage and one disadvantage of this network structure. [2]
(i) Describe one code of conduct that you would expect for each staff. [1]
(ii) Give one example of Multi-Factor Authentication for the staff to prove
their identity. [1]
(i) Describe one code of conduct that you would expect for each staff. [1]
(ii) One staff suggests installing firewall on each computer. Describe one
limitation of firewall. [1]
[Solution]
(ii) Advantage:
Access Control (only authorised personnel can access the data)
Security: less damage if any of the computers at vaccination centre is attacked
Disadvantage:
If the server is down, all the system is down.
Cost more and requires professionals to maintain the system
(b) (i) Conduct: Responsibility, ensure the accuracy and privacy of residents’ data
(ii) MFA: staff card + fingerprint, staff card + password
(c) (i) Professionalism, ensure the system is up-to-date and equipped with protection
schemes
(ii) Limitations:
Hackers can bypass firewall by inserting malicious attacks inside legitimate
programs, for example, emails;
Firewall cannot protect against internal attacks, for example, virus in one
computer in the network;
The setting of firewall may block some legitimate program.
4. (a) State two key characteristics of a recursive function, and when is it suitable to
be used. [3]
(i) Trace the function call P(5, 3), write down the output in the correct
order and the final result returned. [4]
[Solution]
(a)
A function which contains a call to itself.
Should include at least one terminal case – a case that contains no further calls
to the recursive subprogram so that it will not continue indefinitely.
Used when the original task can be reduced to a simpler version of itself
(b) (i)
x n m
5 1 5
5 2 25
5 3 125
Return 125
PollData 12 85 52 57 25 11 33 59 56 91
CardData 11 12 25 52 33 56 57 59 91 85
(a) State why it will take lees time to complete an insertion sort on CardData than
on PollData. [1]
(c) (i) A binary search algorithm is used to find a specific value in an array.
11 12 25 33 52 56 57 59 85 91
Explain how a binary search will find the value 25 in CardData. [4]
(d) Complete this procedure to carry out a binary search on the array show in part
(c)(ii). The missing parts are labelled A, B, C and D. [4]
[Solution]
(b) ArraySize ← 10
ValueToInsert ← CardData[Pointer]
HolePos ← Pointer
CardData[HolePos] ← ValueToInsert
ENDFOR
(c) (i)
• Binary search doesn’t check every value. An unsorted array requires every item to
be checked
• The midpoint is the middle element, not the middle numerical value
• When the higher/lower elements are discarded they will not be the higher/lower
elements
• It might discard the value you are looking for
(ii)
• Find mid-point and comparison // 25 is smaller than/compared to 52/56
• Discard/ignore greater // change upper bound to 33/52/midpoint - 1 //e.g. right
hand side // only use array elements 1 - 4/5
• Find and compare to mid-point of new list e.g. 12/25
• Value is the midpoint // Continue until value found
(d)
A: Last ARRAYLENGTH(CardData)
B: Midpoint (First + Last) DIV 2
C: Last Midpoint – 1
D: First Midpoint + 1
INPUT X
REPEAT
IF X = CardData[pos]
found TRUE
IF found
OUTPUT X, “is at position”, pos
ELSE
OUTPUT X, “ is not in CardData”
ENDIF
OR
pos 1 #initialization
found FALSE
INPUT X
WHILE (NOT found) AND (pos <= 10) AND ( X >= CardData[pos])
IF X = CardData[pos]
found TRUE
ELSE
pos pos + 1
ENDIF
ENDWHILE
IF (found)
OUTPUT X, “is at position”, pos
ELSE
OUTPUT X, “ is not in CardData”
ENDIF
A digital picture can be represented by a 2D array where each cell represents one pixel
and stores its colour as a string. For example, '000000' and 'FFFFFF' represents
black and white colours correspondingly. The following 3 pixel x 3 pixel picture
(b) Modify the array so that all the pixels at the boundaries become black. For
example, [2]
(c) Modify the array so that all the pixels at the diagonals become black. For
example, [2]
(d) Modify the array so that all the pixels in alternate rows become black, starting
from the first row. For example, [2]
(e) A function Search takes in two arguments, N and Pic where Pic is the NxN
array of a random picture. This function searches the array row by row for a
black pixel. If it finds a black pixel, the function stops and returns True.
Otherwise the function returns False.
(a) FOR r 1 to N
FOR c 1 to N
OUTPUT Pic [r, c]
ENDFOR
ENDFOR
(b) FOR i 1 to N
Pic[1, i] '000000'
Pic[i, 1] '000000'
Pic[N, i] '000000'
Pic[i, N] '000000'
ENDFOR
(c) FOR i 1 to N
Pic[i, i] '000000'
Pic[i, N + 1 - i] '000000'
ENDFOR
(e)
FUNCTION Search (N: INTEGER, Pic: ARRAY) RETURNS BOOLEAN
found False
r 1
c 1
RETURN found
ENDFUNCTION
7. A Training Centre conducts programming courses. A programming course has one
session each week and lasts for a number of weeks. Each course studies one particular
programming language.
Customer ID
Customer name
Customer NRIC
Course ID
Language
Start date
Number of weeks
Course tutor
Over a period of time, customers may enrol for many courses. Each course is attended
by a number of customers.
(a) Draw the Entity-Relationship (E-R) diagram to show the tables in third normal
form (3NF) and their relationships between them. [4]
The primary key is indicated by underlining one or more attributes. Foreign keys are
indicated by using a dashed underline.
(b) Using the information given, write table descriptions for the tables you have
identified in part (a). [4]
The database will also store data about tutors and the programming language(s) they
can teach. The following single table, TUTOR, is suggested:
Table: TUTOR
TutorID TutorName LanguageID LanguageName LanguageRank
10 Peter 11 Java 4
9 Python 1
6 C++ 3
63 John 11 Java 4
14 Ruby 5
25 Ken 8 Visual Basic 6
(c) Explain why the TUTOR table is not in first normal form (1NF). [1]
Table: TUTOR
TutorID TutorName
10 Peter
63 John
25 Ken
Table: TUTORLANGUAGE
TutorID LanguageID LanguageName LanguageRank
10 11 Java 4
10 9 Python 1
10 6 C++ 3
63 11 Java 4
63 14 Ruby 5
25 8 Visual Basic 6
(d) State which table is not in second normal form (2NF) and explain why. [2]
(e) Write table descriptions for the tutor and language(s) they teach so that the
revised design is in third normal form (3NF). [2]
(f) With your design in part (e).
(i) Write an SQL query to output the names of tutors and languages for all
languages with rank greater than 4. [4]
(ii) Write an SQL statement to insert a record into Tutor table for tutor Roger
with ID 15. [2]
(g) The centre collects data from customers, describe two data protection
obligations on how the centre must comply with the Personal Data Protection
Act (PDPA). [2]
[Solution]
(a)
(b)
Customer( CustomerID, CustomerName, NRIC )
Course(CourseID, Language, StartDate, NumberOfWeeks, CourseTutor)
CustomerCourse(CustomerID, CourseID)
(c) The table has a repeated group of attributes - Same tutor with multiple languages
recorded.
1. Consent Obligation - Only collect, use or disclose personal data when an individual
has given his/her consent.
4. Access and Correction Obligation - Upon request, the personal data of an individual
and information about the ways in which his or her personal data may have been used
or disclosed in the past year should be provided. Organisations are also required to
correct any error or omission in an individual’s personal data upon his or her request.
5. Accuracy Obligation - Make reasonable effort to ensure that personal data collected
by or on behalf of your organisation is accurate and complete, if it is likely to be used
to make a decision that affects the individual, or if it is likely to be disclosed to another
organisation.
6. Protection Obligation - Make security arrangements to protect the personal data that
your organisation possesses or controls to prevent unauthorised access, collection, use,
disclosure or similar risks.
2001:0db8:0000:0000:0000:ff00:0042:8329.
Note: You may not use the built-in function which converts a hexadecimal string
to an integer.
Sample execution:
For convenience, an IPv6 address may be abbreviated to shorter notations by applying the
following rules, where possible:
One or more leading zeroes from any groups of hexadecimal digits are removed. For
example, the group 0042 is converted to 42.
Consecutive sections of zeroes are replaced with a double colon (::). The double
colon may only be used once in an address, as multiple use would render the address
indeterminate.
An example of application of these rules:
Sample execution:
[Solution]
(a)
def ipv6_hex2dec(ipv6):
gps = ipv6.split(':')
dec_ipv6 = ''
for gp in gps:
decStr = hex2dec(gp)
dec_ipv6 += str(decStr) + ':'
dec_ipv6 = dec_ipv6.rstrip(":")
return dec_ipv6
def hex2dec(hexStr):
decStr = 0
pow = len(hexStr)-1
return decStr
(b)
def expand_ipv6(short_ipv6):
gps = short_ipv6.split(':')
if gps[0] == '':
gps.pop(0)
if gps[-1] == '':
gps.pop(-1)
missingGps = 8 - len(gps) + 1
long_ipv6 = []
for gp in gps:
if gp == '':
for i in range(missingGps):
long_ipv6.append('0000')
else:
gp = (4-len(gp))*'0' + gp
long_ipv6.append(gp)
long_ipv6 = ':'.join(long_ipv6)
return long_ipv6