GATE / CS ARCHIVE

GATE CSE 2004 / QUESTION 6

Level-order traversal

Data Structures · Tree Properties & Traversals · Full GATE CSE 2004 paper

GATE 2004, Q6 1 mark · MCQ
Report issue

Tree Properties & Traversals

Question 6, GATE 2004: Starting at the root, which traversal produces level order in a rooted tree?
Options:
(A) Preorder
(B) Inorder
(C) Depth-first search
(D) Breadth-first search
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. Breadth-first search uses a queue to visit the root, then all children, then their children, and so on. This is precisely level order, D; depth-first traversals do not generally preserve depth order.

2. Teaching check: Begin with just the root in a queue. Repeatedly dequeue a vertex and enqueue its children. Children of a depth-d vertex are enqueued behind all remaining depth-d vertices, so no depth-(d+1) vertex is processed prematurely.

Original paper, page 1