Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
Question 9
Medium

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]

Representing algorithms Questions

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