GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 21

Possible depth-first traversal sequences

Algorithms · Graph Algorithms · Full GATE CSE 2003 paper

GATE 2003, Q21 1 mark · MCQ
Report issue

Graph Algorithms

Question 21, GATE 2003: An undirected graph has vertices {a,b,e,f,g,h} and edges {ae,ab,af,eb,eg,bf,bh,fh,fg,gh}. Which listed sequences can be depth-first traversals starting at a, allowing arbitrary neighbor order? I. a,b,e,g,h,f; II. a,b,f,e,h,g; III. a,b,f,h,g,e; IV. a,f,g,h,b,e. A. I, II and IV only; B. I and IV only; C. II, III and IV only; D. I, III and IV only.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Step through it (4 options)

1. DFS must finish every reachable unexplored neighbor before returning from a vertex. The three accepted sequences can be realized without any backtrack until all six vertices are visited because each consecutive pair is an edge. In II the transition from f to e would require backtracking through b, but f still has unvisited neighbors g and h, so DFS cannot yet leave f. Hence e cannot be next.

2. I, III and IV each trace a simple path through all vertices using displayed edges, so a neighbor order realizes each. In II, f has no edge to e and still has unvisited neighbors g and h; DFS must visit one of these before backtracking. Thus II is impossible and the answer is D.

Original paper, page 3