Chapter 16 SB Answers
Chapter 16 SB Answers
Cambridge International AS & A Level Computer Science Answers
b)
Static libraries – where software being developed is linked to executable code in the library at
the time of compilation. The library routines would be embedded directly into the new program
code.
Dynamic – where software being developed is not linked to the library routines until actual run
time (these are known as dynamic link library files or DLL). These library routines would be
stand-alone files only being accessed as required by the new program. The routines will be
available to several applications at the same time).
Activity 16A
1 A 6 D 11 E
2 B 7 E 12 C
3 B 8 C 13 E
4 C 9 B 14 A
5 E 10 A 15 E
Cambridge International AS & A Level Computer Science Answers
Activity 16B
34 85 04 83
Activity 16C
1 Valid variables are:
A1 letter (must be A, B or C) followed by digit (must be 1, 2 or 3)
C3 letter (must be A, B or C) followed by digit (must be 1, 2 or 3).
2 Invalid statements are:
A1 = A1 + B1 + C1 can only have 2 variables on the right-hand side of the assignment
statement
A1 := C1 – C2 := is not included in the syntax diagram for an assignment statement.
Activity 16D
Letter Digit
Variable
Letter
Letter Digit
A 0
B 1
C
2
D
3
4
Cambridge International AS & A Level Computer Science Answers
Activity 16E
<integer> ::= <digit> | <integer> <digit>
Activity 16F
1 Lexical analysis, Syntax analysis, Code generation and Optimisation
– see section 16.3.2
2 a)
Letter Digit
I
0
J 1
K 2
3
4
Assignment
Variable = Variable Operator Variable
+
‐
Cambridge International AS & A Level Computer Science Answers
3 a) i) A B C D * + +
ii) A B C + + D *
iii) A B + D * A B – C * +
b) i)
2
5 10
3 3 13
7 7 7 20
ii)
5
3 8 2
7 7 15 30
iii)
3 5
3 2 7 4 4 20
7 10 20 20 20 20 20 40
Cambridge International AS & A Level Computer Science Answers
ii)
page presence flag page frame address additional data
6 1 221 12:07:34:49
iii)
When the procedure call is made, Page 1 is swapped out and Page 3 is swapped in.
At the end of the procedure call, Page 3 is swapped out and Page 1 is swapped in.
Page 1/3 is always in memory the shortest amount of time.
The entire sequence is repeated for every iteration.
iv) Thrashing/continuously swapping pages
3 a) quantum g) non-preemptive
b) pre-emptive
h) burst
c) virtual memory
i) segmentation
d) low level scheduler
j) starvation
e) context switching
f) paging
Cambridge International AS & A Level Computer Science Answers
b) i) FIFO:
When using first in first out (FIFO), the OS keeps track of all pages in memory using a
queue structure
The oldest page is at the front of the queue and is the first to be removed when a new page
needs to be added.
FIFO algorithms don’t consider page usage when replacing pages; a page may be replaced
simply because it arrived earlier than another page.
It suffers from, what is known as, Belady’s Anomaly where it is possible to have more
page faults when increasing the number of page frames.
ii) OPR:
Optimal page replacement looks forward in time to see which frame it can replace in the
event of a page fault.
The algorithm is actually impossible to implement; at the time of a page fault, the OS has
no way of knowing when each of the pages will be replaced next.
It tends to get used for comparison studies but has the advantage that it is free of Belady’s
Anomaly and also has the fewest page faults.
iii) LRU:
With least recently used page replacement (LRU), the page which has not been used for
the longest time is replaced.
To implement this method, it is necessary to maintain a linked list of all pages in memory
with the most recently used page at the front and the least recently used page at the rear.
6 a)
b) paging is fixed size; segmentation is variable size; pages are smaller than segments
c) Types of interrupts
device interrupt (e.g. printer out of paper)
exception (e.g. division by zero)
trap/software interrupt (e.g. software needs to access/use a resource).
Cambridge International AS & A Level Computer Science Answers
7 a)
Token
Symbol
Value Type
Start 60 Variable
0.1 61 Constant
Counter 62 Variable
10 63 Constant
b)
60 01 61 4E 62 01 60 50 63 52 62 02 60 53
c) i) Syntax analysis
ii) Checking the grammar of the program and producing an error report.
d) i) Minimise the time taken to execute the program.
ii) Replace 2 * 6 with the value 12
iv)
LDD 436
ADD 437
STO 612
ADD 438
STO 613
8 a) i) There should be a colon before the equals sign.
ii) The second operand should be an unsigned integer and not a variable.
iii) A32 is not a variable, as a variable should be a letter followed by a single digit.
b)
<assignment_statement> ::= <variable> := <variable> <operator>
<unsigned_integer>
<variable> ::= <letter> <digit>
<unsigned_integer> ::= <digit> | <digit> <unsigned_integer>
<letter> ::= A | B | C
<operator> ::= + | - | * | ^
c)
Variable
d)
<assignment_statement> ::= <variable> := <variable> <operator> <real>
Cambridge International AS & A Level Computer Science Answers
9 a)
Statement Compilation stage
This stage can improve
the time taken to execute Lexical analysis
the statement: x = y + 0
b) P Q + R S / -
c) i)
2
3 3 5
2 1 1 1 1 6
2 2 4 4 4 4 4 4 -2
ii) b * a - (c + d + a)
iii) In RPN evaluation of operators is left to right so there is no need for brackets to
establish precedence.