Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

2019 C1 Promo Exam Suggested Solution

Question 1
(a) IP address is the logical address of a device in the network
MAC address is the physical address of a device.
(b) IPv4 uses decimal numbers but IPv6 uses hexadecimal numbers.
OR IPv4 is 32 bit and IPv6 is 128 bit

Question 2
 Need of TCP: establishes connection before data is transmitted.
 3-Way Handshake: User A send a SYN request to User B, User B sends back a SYN/ACK
message to acknowledge, User A sends another ACK message to establish the connection
 Advantage of TCP: Reliable connection; ensure the order of the data; In case of data loss,
TCP can resend the data

Question 3
(a) high security level within the campus; faster communication and collaboration for
students and staff; reduce the cost of connecting all devices to the Internet
(b) monitors and controls all incoming and outgoing network traffic based on a set of
security rules, detect a malicious document and block it from entering the network.
Limitation: cannot protect against internal attack; the setting of firewall may block
some legitimate programs
(c) Encryption ensures only authorised person can access the document.
Digital signature ensures the document was created by the known sender
OR digital signature ensures that the document was not altered in transit.

Question 4
(a) The file contains repeated information. For example: student name, phone number, title
are repeated and stored in multiple records.
(b)
Student StudentLoan Book
(c)
Book (BookID, BookTitle)
Student (StudentID, StudentName, PhoneNumber)
StudentLoan (LoanID, StudentID, BookID, DateBorrowed, DateDue, DateReturned)
OR StudentLoan(StudentID, Book ID, DateBorrowed, DateDue, DateReturned)

(d)
(i) SELECT StudentName, PhoneNumber FROM Student

(ii) SELECT Book.BookTitle, StudentLoan.DateBorrowed, StudentLoan.DateReturned


FROM StudentLoan INNER JOIN Book ON StudentLoan.BookID= Book.BookID
WHERE StudentLoan.StudentID = 3

OR SELECT Book.BookTitle, StudentLoan.DateBorrowed, StudentLoan.DateReturned


FROM StudentLoan, Book WHERE StudentLoan.bookID= Book.BookID
AND StudentLoan.StudentID = 3

(e) any two from below + student data related to the question (e.g. phone number)
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.

(f)

Backup Archive
Enables rapid recovery of live, changing data Stores unchanging data no longer in use but
must be retained
Multiple copies of data One copy
Restore speed: crucial Retrieval speed: not crucial
Short Term Retention Long Term Retention
Retained for as long as data is in active use Retained for required period or indefinitely
Duplicate copies are periodically overwritten Data cannot be altered or deleted

(g)
Version Control
1.Ease collaboration across distributed teams -a version control system makes it much easier
to share code changes and coordinate the work of the various team members who are
responsible for the database. The ability to rapidly share and manage changes makes it
particularly important for teams based in different locations, and evidence shows that teams
are increasingly distributed.
2.Gain better visibility of the development pipeline -a version control system provides an
overview of what development work is going on, its progress, who’s doing it, and why. It also
maintains detailed change histories and can be associated with issue tracking systems.
3.Ability to roll back or retrieve previous versions- it provides an efficient mechanism for
backing up the code. Because the history it provides is incremental, version control lets
developers explore different solutions and roll back safely in the case of errors.
4. More readily demonstrate compliance and auditing -The change tracking provided by
version control is the first step to getting ready for compliance, and an essential step in
maintaining a robust audit trail and managing risk. Compliance auditors will require an
organization to account for all changes and detail all those with access to it.

Naming Convention
1. Readability is important. Readability helps in figuring out what the code does in less time.
2. A common naming convention that everyone agrees to follow will result in developers,
reviewers and project managers communicate effectively with respect to what the code does.
3. Naming conventions result in improvements of communication, code integration,
consistency and clarity and lead to predictability and discoverability (easier to find files)

Question 5
1 Assume array index starts at 1
2
3 xptr = 1
4 yptr = 1
5 zptr = 1

6 While xptr <= M and yptr <= N


7 If X[xptr] < Y[yptr]
8 Z[zptr] = X[xptr]
9 zptr = zptr + 1
10 xptr = xptr + 1
11 Else
12 Z[zptr] = Y[yptr]
13 zptr = zptr + 1
14 yptr = yptr + 1
15 Endif
16 EndWhile

17 If xptr <= M
18 For i = xptr to M
19 Z[zptr] = X[i]
zptr = zptr + 1
20 EndFor
21 EndIf
22
23 If yptr <= N
24 For i = yptr to N
25 Z[zptr] = Y[i]
zptr = zptr + 1
26 EndFor
27 EndIf
Question 6
Method 1
Assume string index starts at 0
1 Output(“Key in a word:”)
2 Input word
3
4 found = False
5 i=0

6 While (Not found) and ( i <= len(word) -3 )


7 If (ascii(word[i]) = ascii(word[i+1]) - 1 )
8 and (ascii(word[i+1]) = ascii(word[i+2]) – 1 )
9 found = True
10 EndIf
11 i=i+1
12 EndWhile

13 If found = True
14 output(“Yes”)
15 Else
16 output(“No”)
17 EndIf

Method 2
1 Assume string index starts at 0
2 Output(“Key in a word:”)
3 Input word
4 nooftime = 1
5 current = 0
6 previous = 0
7
8 n = 0
9 hasThreeChars = False

10 While hasThreeChars = False and n < len(word)


11
12 current = ord(word[n])
13 If current – previous = 1
14 nooftime = nooftime + 1
15 Else
16 nooftime = 1
17 EndIf
18 previous = current
19 If nooftime = 3
20 hasThreeChars = True
21 EndIf
22 n = n + 1
23 EndWhile

24 If hasThreeChars = True
25 Output(“Yes”)
26 Else
27 Output(“No”)
28 EndIf
Question 7
(i)
000 996258

996 996123
997 996514
998 998330
999 996001

(ii)
read the ID code and extract the first three digit as the block number to search for
1. if the block is empty, no record exists with the ID code
2. if the block contains the ID code, the record is found
3. if the block contains another ID code other than the one we are searching, begin a
‘circular’ linear search from this block onwards until
a. the ID code we are searching is found OR
b. we reach an empty block, indicating no record exists with the ID code OR
c. we reach the starting block of the ‘circular’ linear search, also indicating no record

Question 8
(a) MYS, AUS, CAN, SGP, JPN.
MYS
Insert AUS: AUS MYS
Insert CAN: AUS CAN MYS
Insert SGP: AUS CAN MYS SGP
Insert JPN: AUS CAN JPN MYS SGP

(b) (i) A: UpperBound – 1 B: List [ Posn + 1 ]


C: False D: Temp
(ii) 2 passes. The list is mostly sorted in ascending order. Once there is no swap in a pass,
the sorting process is done.
Question 9
FUNCTION check_solution (grid, magic_sum, order)

# Check to make sure that integers in the grid are unique


IF check_numbers (grid, order) = FALSE
RETURN FALSE

# Check if rows are valid


IF check_rows (grid, magic_sum, order) = FALSE
RETURN FALSE

# Check if columns are valid


IF check_cols (grid, magic_sum, order) = FALSE
RETURN FALSE

# Finally, check if diagonals are valid


IF check_diagonals (grid, magic_sum, order) = FALSE
RETURN FALSE

# Since all 3 checks report the grid is valid,


# then the magic square solution is valid
RETURN TRUE

ENDFUNCTION

""" Verifies that each integer in the magic grid is unique """
FUNCTION check_numbers (grid, order):

#set up a number_list of unique numbers from 1 to order^2


number_list  list(range(1, order^2))

FOR row  1 to order


FOR col  1 to order
number  grid[row][col]
IF number IN number_list
number_list.remove(number)
ENDIF
ENDFOR
ENDFOR

IF number_list = []
RETURN TRUE
ELSE
RETURN FALSE
ENDIF

ENDFUNCTION
""" Checks each row in the grid to make sure it is valid """
FUNCTION check_rows (grid, magic_sum, order)

row_sum_valid  TRUE
row  1

WHILE (row_sum_valid) AND (row <= order)


row_sum  0
FOR col  1 to order
row_sum  row_sum + grid[row][col]
ENDFOR

IF row_sum <> magic_sum


row_sum_valid  FALSE
ELSE
row  row + 1
ENDIF
ENDWHILE

RETURN row_sum_valid

ENDFUNCTION

""" Checks each col in the grid to make sure it is valid """
FUNCTION check_cols (grid, magic_sum, order)

col_sum_valid  TRUE
col  1

WHILE (col_sum_valid) AND (col <= order)


col_sum  0
FOR row  1 to order
col_sum  col_sum + grid[row][col]
ENDFOR

IF col_sum <> magic_sum


col_sum_valid  FALSE
ELSE
col  col + 1
ENDIF
ENDWHILE

RETURN col_sum_valid

ENDFUNCTION
""" Checks the two diagonals """
FUNCTION check_diagonals (grid, magic_sum, order)

# diagonal 1 (top left downto bottom right)


diagonal_sum1  0
FOR i  1 to order
diagonal_sum1  diagonal_sum1 + grid[i][i]
ENDFOR

# diagonal 2 (top right downto bottom left)


diagonal_sum2  0
row  1
col  order
FOR i  1 to order
diagonal_sum2  diagonal_sum2 + grid[row][col]
row  row + 1
col  col - 1
ENDFOR

IF diagonal_sum1 = diagonal_sum2 = magic_sum


RETURN TRUE
ELSE
RETURN FALSE
ENDIF

ENDFUNCTION

BEGIN_MAIN()

order, grid  ReadMatrix()


magic_sum  sum (grid[1]) # sum of numbers in the 1st row

IF check_solution (grid, magic_sum, order) = TRUE


OUTPUT (‘Valid Solution')
ELSE
OUTPUT ('Invalid Solution')
ENDIF

END_MAIN
Question 10
(a)
 iterative solution is a loop which converges to a solution
recursive solution is a procedure which keeps calling itself until a solution is found
 iterative solution: successive values of its local variables are overwritten
recursive solution: successive values of its local variables are all preserved

(b) (i) PROCEDURE SHRINK(aString, n)


FOR i = 1 to n
PRINT (' ', end ='')
ENDFOR
PRINT (aString)

IF length of aString = 1
RETURN
ELSE
SHRINK(BUTFIRST(aString), n+1)

ENDIF

FOR i = 1 to n
PRINT (' ', end ='')
ENDFOR
PRINT (aString)
ENDPROCEDURE

(ii) To indicate the number of spaces to print before the string for right justification

You might also like