logo

Question detail

A depth-first search is used to navigate a maze. From S, the available routes are considered in this order: S connects to A and B; A connects to C; C connects to D; D is a dead end; B connects to E; E connects to G. Trace the order of first visits until G is reached, including the backtracking that is needed.

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

Question

Type

practice

Style

Topic

Graph-traversal

Exam-style question

Try this first

A depth-first search is used to navigate a maze. From S, the available routes are considered in this order: S connects to A and B; A connects to C; C connects to D; D is a dead end; B connects to E; E connects to G. Trace the order of first visits until G is reached, including the backtracking that is needed.

Model answer

What a good answer should say

  • The first-visit order is S, A, C, D, B, E, G.
  • The search follows S-A-C-D, reaches the dead end D, backtracks to C, then A and S, and takes the untried route S-B-E-G.

Explanation

Why this works

Depth-first search follows the first route as far as it can. After reaching D, there is no unvisited continuation, so it backtracks through C and A to S.

It then explores B, followed by E, and reaches G.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.