14 original exam-style questions - 10 pages of questions with a full mark scheme - free printable PDF.
IF NOT (hasCoin AND buttonPressed) THEN OUTPUT "Please insert a coin and press the button" ENDIF
FOR i <- 0 TO 3
FOR j <- 0 TO 3 - i
IF scores[j] > scores[j + 1] THEN
temp <- scores[j]
scores[j] <- scores[j + 1]
scores[j + 1] <- temp
ENDIF
NEXT j
NEXT iFUNCTION Fibonacci(n)
DECLARE cache : ARRAY[0:n] OF INTEGER
cache[0] <- 0
cache[1] <- 1
FOR i <- 2 TO n
cache[i] <- cache[i - 1] + cache[i - 2]
NEXT i
RETURN cache[n]
ENDFUNCTIONComplete a trace table showing the value stored in cache[i] for each value of i from 2 to 6, when Fibonacci(6) is called.(3)FUNCTION FindPath(x, y)
IF grid[x][y] = "E" THEN
RETURN TRUE
ENDIF
IF NOT ValidMove(x, y) THEN
RETURN FALSE
ENDIF
MarkVisited(x, y)
IF FindPath(x + 1, y) THEN
RETURN TRUE
ENDIF
IF FindPath(x, y + 1) THEN
RETURN TRUE
ENDIF
IF FindPath(x - 1, y) THEN
RETURN TRUE
ENDIF
IF FindPath(x, y - 1) THEN
RETURN TRUE
ENDIF
RETURN FALSE
ENDFUNCTIONValidMove(x, y) returns TRUE only if (x, y) is inside the grid, is not a wall, and has not already been visited during this search.arrival[1] <- 0
arrival[2] <- 4
arrival[3] <- 5
arrival[4] <- 9
arrival[5] <- 15
service[1] <- 6
service[2] <- 3
service[3] <- 5
service[4] <- 4
service[5] <- 2
finishPrev <- 0
totalWait <- 0
FOR i <- 1 TO 5
IF arrival[i] > finishPrev THEN
start[i] <- arrival[i]
ELSE
start[i] <- finishPrev
ENDIF
finish[i] <- start[i] + service[i]
wait[i] <- start[i] - arrival[i]
finishPrev <- finish[i]
totalWait <- totalWait + wait[i]
NEXT iIF (NOT hasCoin) OR (NOT buttonPressed) THEN OUTPUT "Please insert a coin and press the button" ENDIF
FOR i <- 0 TO n
cache[i] <- -1
NEXT i
FUNCTION Fibonacci(n)
IF n <= 1 THEN
RETURN n
ENDIF
IF cache[n] <> -1 THEN
RETURN cache[n]
ENDIF
cache[n] <- Fibonacci(n - 1) + Fibonacci(n - 2)
RETURN cache[n]
ENDFUNCTION