The part that tripped me up initially was the coordinate tracking.
Treat the problem as online exploration of an unknown graph where the mouse maintains a relative coordinate system and a map of visited cells. Use a systematic exploration strategy like depth-first search with backtracking, leveraging the ability to turn and move to navigate back to known cells. Argue that the algorithm guarantees finding the cheese because it exhaustively explores all reachable cells, and analyze complexity in terms of the number of moves relative to the maze size.
Pro tip: Emphasize that the mouse must maintain its orientation and use relative coordinates to build a consistent map; this is crucial for backtracking and avoiding infinite loops. Also, discuss how the algorithm handles dead ends and revisits efficiently.
Represent the maze as an unknown grid graph where each cell has up to four neighbors. The mouse's state includes its relative position (x, y) and orientation (facing direction).
Select a systematic exploration algorithm such as depth-first search (DFS) with backtracking. The mouse will explore each branch fully before returning to explore other branches.
Maintain a map of visited cells and their connectivity. Use the move and turn operations to navigate: to move to an adjacent cell, turn to face it, then move forward. To backtrack, reverse the path using the map.
Prove that the algorithm explores all reachable cells: since the maze is finite and connected, DFS will eventually visit every cell, including the one with cheese. The relative coordinate system ensures no cell is missed due to orientation changes.
The number of moves is O(N) where N is the number of reachable cells, but constant factors depend on backtracking. Each edge may be traversed multiple times, but the total moves are bounded by O(N * D) where D is the maximum degree (4). Space complexity is O(N) for the map.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.