You are on page 1of 16

2021 C1 Promo Exam Suggested Solution

1. Explain the purpose and give one example for each of the following techniques:

(a) Data Validation [2]

(b) Data Verification [2]

[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]

(c) Describe two differences between switch and router. [2]

[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.

(i) State the name of such network structure. [1]

(ii) Give one advantage and one disadvantage of this network structure. [2]

(b) Admin staff is in charge of handling the residences’ data.

(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]

(c) IT staff is in charge of maintaining the computer systems in the vaccination


centre.

(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]

(a) (i) client-server network.

(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]

(b) Consider the following pseudocode algorithm:

01 FUNCTION P(x: INTEGER, n: INTEGER) RETURNS INTEGER


02 IF n = 0
03 THEN
04 RETURN 1
05 ELSE
06 m  x * P(x, n-1)
07 OUTPUT (x, n, m)
08 RETURN m
09 ENDIF
10 ENDFUNCTION

(i) Trace the function call P(5, 3), write down the output in the correct
order and the final result returned. [4]

(ii) Describe the purpose of function P. [1]

[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

(ii) Calculates x to the power of n

5. The arrays PollData[1:10] and CardData[1:10] store data.

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]

(b) Write an algorithm, in pseudocode, that performs an insertion sort on the


CardData array. [5]

(c) (i) A binary search algorithm is used to find a specific value in an array.

Explain why an array needs to be sorted before a binary search algorithm


can be used. [2]

(ii) The current contents of CardData are shown.

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]

PROCEDURE BinarySearch(CardData, SearchValue)


First  1
Last  ARRAYLENGTH(. . . . A . . . .)
FOUND  FALSE
WHILE (First <= Last) AND (NOT Found)
Midpoint  . . . . B . . . .
IF CardData[Midpoint] = SearchValue
Found  TRUE
ELSE IF SearchValue < CardData[Midpoint]
Last  . . . . C . . . .
ELSE
First  . . . . D . . . .
ENDIF
ENDWHILE
ENDPROCEDURE

(e) Using the contents of CardData shown in (c)(ii). Write an algorithm, in


pseudocode, for a linear search that will read a value, X, and output the position
of X or output a message stating that X is not in CardData. [5]

[Solution]

(a) CardData is partially sorted/ordered // more items in order/sorted.

(b) ArraySize ← 10

FOR Pointer ← 2 TO ArraySize

ValueToInsert ← CardData[Pointer]
HolePos ← Pointer

WHILE (HolePos > 1) AND (CardData[HolePos - 1] > ValueToInsert)


CardData[HolePos] ← CardData[HolePos – 1]
HolePos ← HolePos – 1
ENDWHILE

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

(e) pos  1 #initialization


found  FALSE
exitLoop  FALSE

INPUT X

REPEAT
IF X = CardData[pos]
found  TRUE

ELIF X < CardData[pos]


exitLoop  TRUE

ELSE // X > CardData[pos]


pos  pos + 1
IF pos > 10 // index out of range
exitLoop  TRUE
ENDIF
ENDIF
UNTIL (found = TRUE) OR (exitLoop = 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

6. Assume array index starts with 1 in this question.

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

     
     
     

can be represented by the 2D array below:

'000000' 'FFFFFF' '000000'


'FFFFFF' '000000' 'FFFFFF'
'000000' 'FFFFFF' '000000'
Given a random picture represented by a 2D array Pic of size N x N. Write an algorithm,
in pseudocode, to perform each of the following tasks:

(a) Output the 2D array. [2]

(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.

Write the function in pseudocode with the following specification:

FUNCTION Search (N: INTEGER, Pic: ARRAY) RETURNS BOOLEAN


[8]
[Solution]

(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

(d) FOR r  1 to N STEP 2


FOR c  1 to N
Pic[r, c]  '000000'
ENDFOR
ENDFOR

(e)
FUNCTION Search (N: INTEGER, Pic: ARRAY) RETURNS BOOLEAN
found  False
r  1
c  1

WHILE found = False AND r <= N


WHILE found = False AND c <= N
IF Pic[r, c] <> '000000'
c  c + 1
ELSE
found  True
ENDIF
ENDWHILE
r  r + 1
ENDWHILE

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.

Each customer has the following data recorded:

 Customer ID
 Customer name
 Customer NRIC

Each course has the following data recorded:

 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.

The data are to be stored in a relational database.

(a) Draw the Entity-Relationship (E-R) diagram to show the tables in third normal
form (3NF) and their relationships between them. [4]

A table description can be expressed as:

TableName( Attribute1, Attribute2, Attribute3, …)

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]

The following is an attempt to reduce data redundancy:

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)

Customer CustomerCourse Course

(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.

(d) TUTORLANGUAGE table


Table has composite key formed by TutorID and LanguageID, but LanguageName
and LanguageRank is dependent on only part of the primary key, LanguageID.

(e) Tutor( TutorID, TutorName)


Language(LanguageID, LanguageName, LanguageRank)
TutorLanguage (TutorID, LanguageID)

(f) (i) SELECT Tutor.TutorName, Language.LanguageName


FROM Tutor
INNER JOIN TutorLanguage
ON Tutor.TutorID = TutorLanguage.TutorID
INNER JOIN Language
ON Language.LanguageID = TutorLanguage.LanguageID
WHERE Language.Rank > 4

(ii) INSERT INTO Tutor(TutorID, TutorName) VALUES (15, 'Roger')


(g) Any 2.

1. Consent Obligation - Only collect, use or disclose personal data when an individual
has given his/her consent.

2.Purpose Limitation Obligation - An organisation may collect, use or disclose


personal data about an individual for the purposes that a reasonable person would
consider appropriate in the circumstances and for which the individual has given
consent.

3.Notification Obligation - Notify individuals of the purposes for which your


organisation is intending to collect, use or disclose their personal data on or before
such collection, use or disclosure of personal data.

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.

7. Retention Limitation Obligation - Cease retention of personal data or remove the


means by which the personal data can be associated with particular individuals when
it is no longer necessary for any business or legal purpose.

8. Transfer Limitation Obligation -Transfer personal data to another country only


according to the requirements prescribed under the regulations, to ensure that the
standard of protection provided to the personal data so transferred will be comparable
to the protection under the PDPA.

9. Accountability Obligation -Make information about your data protection policies,


practices and complaints process available on request.
8. The 128 bits of an IPv6 address are represented in 8 groups of 16 bits each. Each group is
written as 4 hexadecimal digits and the groups are separated by colons (:). An example
of this representation is the address

2001:0db8:0000:0000:0000:ff00:0042:8329.

(a) Write, in Python code, a function ipv6_hex2dec(ipv6) to convert an IPv6


address to decimal. [7]

Note: You may not use the built-in function which converts a hexadecimal string
to an integer.

Sample execution:

>>> print (ipv6_hex2dec("0000:0000:0000:0000:0000:0000:0000:000f"))


0:0:0:0:0:0:0:15

>>> print (ipv6_hex2dec ("fdb1:344c:33da:0000:0040:0000:0000:0000"))


64945:13388:13274:0:64:0:0:0

>>> print (ipv6_hex2dec("2001:0db8:0000:0000:0000:ff00:0042:8329"))


8193:3512:0:0:0:65280:66:33577

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:

Initial address: 2001:0db8:0000:0000:0000:ff00:0042:8329


After removing all leading zeroes: 2001:db8:0:0:0:ff00:42:8329
After omitting consecutive sections of zeroes: 2001:db8::ff00:42:8329
(b) Write, in Python code, a function expand_ipv6(short_ipv6) to convert
an abbreviated IPv6 address to its original form. [7]

Sample execution:

>>> print (expand_ipv6 ("2001:db8::ff00:42:8329"))


2001:0db8:0000:0000:0000:ff00:0042:8329

>>> print (expand_ipv6 ("::f"))


0000:0000:0000:0000:0000:0000:0000:000f

>>> print (expand_ipv6 ("fdb1:344c:33da:0:40::"))


fbd1:344c:33da:0000:0040:0000:0000:0000

[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):

dec = {'a':10, 'b':11, 'c':12, 'd':13, 'e':14, 'f':15}

decStr = 0
pow = len(hexStr)-1

for char in hexStr:


if char.isdigit():
decStr += int(char) * (16 ** pow)
else:
decStr += dec[char] * (16 ** pow)
pow -= 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

You might also like