Professional Documents
Culture Documents
(b) (i)
(c) (i)
2 F F T F F F F F
1
6 T F F F F F F F
1
(ii) S[i,j] = T 1
C[j] C[j] + 1 2
1
2. (a) (i) Stack. Element can only be inserted at the top of the stack while element in linked list can be
inserted anywhere in the list. 1+1
OR
Queue. Element can only be enqueued at the end of the queue while element in linked list can be
inserted anywhere in the list. 1+1
(iv) D, C, G , F 2
(v) 6 1
(b) Address UNIT NEXT
0 START 1
1 A 3
2 E 4
3 F 7
4 B 5
5 D 8
6 C 2
7 G 6
8 H -2
All Correct 2 ORs
4 rows or above 1
(c) (i) The linked list can be transverse into two ways. 1
All Correct 1
(iii) NEXT[Z] 1
PREV[Z] 1
2
3. (a) (i)
swap(item[j], item[j+1]) 2
(c) (i) 6 1
(ii) 0 1
(d) True 1
1 to n-1 1
item[i] > item[i+1] 1
Valid False 1
Valid 1
4. (a) True 1
data[j] = data[k] 1
Or 1
checkUniq(AR) 1
(c)
checkSol():
result true;
for i 0 to 8 do
if not checkCol(i) or not checkRow(i) or not checkBox(i)
then
result false
return result
3
(d) Marking Scheme
Validation 1 mark
Converting the row and col from 1-9 to 0-8 1 mark
Correct logic on finding and outputting the hints 3 marks
All correct (including syntax) 1 mark
{C Version}
void findHints(int row, int col) {
int r[9];
int t;
int i, j;
for (t = 0; t < 9; t++) //Initialize the result array
r[t] = 1;
i = row - 1;
j = col - 1;
if (i > 8 || i < 0 || j > 8 || j < 0 || sol[i][j] != 0) { //Validation
printf("NA");
} else {
for (t = 0; t < 9; t++) {
/* Check Row */
if (sol[i][t] != 0)
r[sol[i][t]-1] = 0;
/* Check Col */
if (sol[t][j] != 0)
r[sol[t][j]-1] = 0;
/* Check Box */
if ( sol[ (i/3)*3+(t/3) ][ (j/3)*3+t%3 ] != 0)
r[ sol[ (i/3)*3+(t/3) ][ (j/3)*3+t%3 ] - 1 ] = 0;
}
for (t = 0; t < 9; t++) { //Output
if (r[t] == 1)
printf("%d", t+1);
}
}
}
{Pascal Version}
procedure findHints(row, col : integer);
var
t, i, j : integer;
r : array[0..8] of integer;
begin
for t := 0 to 8 do
r[t] := 1;
i := row - 1;
j := col - 1;
{ Validation }
if (i > 8) or (i < 0) or (j > 8) or (j < 0) or (sol[i, j] <> 0) then
writeln('NA')
else
begin
for t := 0 to 8 do
begin
{ Check Row }
if (sol[i, t] <> 0) then
r[sol[i, t]-1] := 0;
{ Check Col }
if (sol[t, j] <> 0) then
r[sol[t, j]-1] := 0;
{ Check Box }
if ( sol[(i div 3)*3+(t div 3),(j div 3)*3 + t mod 3] <> 0) then
r[ sol[(i div 3)*3+(t div 3),(j div 3)*3 + t mod 3]-1] := 0;
end;
{ Output }
for t := 0 to 8 do
if (r[t] = 1) then
Write(t+1);
end;
end;
4
{Java Version}
public static void findHints(int row, int col) {
int[] r = new int[9];
int t;
int i, j;
for (t = 0; t < 9; t++) //Initialize the result array
r[t] = 1;
i = row - 1;
j = col - 1;
if (i > 8 || i < 0 || j > 8 || j < 0 || sol[i][j] != 0) { //Validation
System.out.printf("NA");
} else {
for (t = 0; t < 9; t++) {
/* Check Row */
if (sol[i][t] != 0)
r[sol[i][t]-1] = 0;
/* Check Col */
if (sol[t][j] != 0)
r[sol[t][j]-1] = 0;
/* Check Box */
if ( sol[ (i/3)*3+(t/3) ][ (j/3)*3+t%3 ] != 0)
r[ sol[ (i/3)*3+(t/3) ][ (j/3)*3+t%3 ] - 1 ] = 0;
}
for (t = 0; t < 9; t++) { //Output
if (r[t] == 1)
System.out.printf("%d", t+1);
}
}
}
for t = 0 to 8
r(t) = 1
Next
i = row - 1
j = col - 1
'Validation
if (i > 8) or (i < 0) or (j > 8) or (j < 0) or (sol(i, j) <> 0) then
Console.Write("NA")
else
for t = 0 to 8
' Check Row
if (sol(i, t) <> 0) then
r(sol(i, t)-1) = 0
End if
' Check Col
if (sol(t, j) <> 0) then
r(sol(t, j)-1) = 0
End If
' Check Box
if ( sol( (i \ 3)*3+(t \ 3) , (j \ 3)*3 + (t mod 3) ) <> 0) then
r( sol( (i \ 3)*3+(t \ 3) , (j \ 3)*3 + t mod 3 ) - 1 ) = 0
End If
Next
End If
' Output
for t = 0 to 8
if (r(t) = 1) then
Console.Write(t+1)
End if
Next
end Sub