Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
Question 5
Medium

A robot is placed in a 5x5 grid. The position of each cell is described using coordinates in the format (column, row), where columns are numbered 1 to 5 from left to right, and rows are numbered 1 to 5 from bottom to top.

The Grid Layout

Row (y)Column 1 (x)Column 2 (x)Column 3 (x)Column 4 (x)Column 5 (x)
5
4[Object]
3→ (Start)[Object]
2
1[Object]

A 5x5 grid with columns 1 to 5 from left to right and rows 1 to 5 from bottom to top. Black obstacle squares (objects) are located at (3,4), (4,3), and (3,1). The robot starts at (3,3) facing East (represented by a right arrow →).

  • The robot starts at (3,3) facing East (rightwards, towards column 4).
  • Cells labeled [Object] are black squares containing obstacles.
  • The boundary (outer edge) of the 5x5 grid also counts as an object (i.e. ObjectAhead() returns true if the robot is facing the edge of the grid).

Trace the execution of the following algorithm:

WHILE ObjectAhead() = true
  TurnLeft()
  IF ObjectAhead() = true THEN
    TurnRight()
    TurnRight()
  ENDIF
  Forward(1)
ENDWHILE
Forward(1)

State the sequence of grid coordinates visited by the robot in order, starting from its initial position (3,3) to its final position using the format: (3,3) -> (x,y) -> ...

[3]

Representing algorithms Questions

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