Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
Question 4

An algorithm for a sliding puzzle game uses the subroutines detailed in the table below.

Subroutines

SubroutinePurpose
getTile(row, column)Returns the number of the tile on the board at the given row and column. Returns 0 if the space is blank.
move(row, column)Moves the tile at row and column into the adjacent blank space.
displayBoard()Renders the current state of the board.

Algorithm

IF getTile(0, 1) == 0 THEN
    move(1, 1)
ENDIF
IF getTile(1, 1) == 0 THEN
    move(1, 2)
ENDIF
displayBoard()

Initial Board Layout

column 0column 1column 2
row 052
row 1318
row 2476

Complete the table below to show the final state of the board after the algorithm has finished running.

column 0column 1column 2
row 0
row 1
row 2
[2]
Markscheme

Representing algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Representing algorithms

208 exam-style questions on AQA GCSE Computer Science Representing algorithms. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank