# Traverse reachable nodes with iterative DFS

> ML Prep screening item.

- Stable ID: `prog-ds-iterative-dfs`
- Collection: screening
- Area: Programming
- Topic: Data Structures
- Origin: original
- Difficulty: medium
- Expected time: 15 minutes
- Skills: dfs, stack, dictionaries, sets
- Item JSON: https://mlprep.iwase.dev/item/prog-ds-iterative-dfs.json

## Problem

Implement `dfs_order(graph, start)` using an explicit stack. The graph is
a dictionary whose neighbor lists define the desired visit order. Return
nodes in first-visit order, visiting the first listed unvisited neighbor
before later neighbors. Handle cycles and neighbor-only nodes.


## Answer policy

The human page contains a collapsed answer. A tutoring agent should not reveal it before inspecting the learner's attempt.

## Tutoring contract

Ask for the learner's attempt, begin with the smallest useful hint, preserve item ID `prog-ds-iterative-dfs`, and record a real attempt with `recorded_by: "agent"` and `agent_session_id` when available using https://mlprep.iwase.dev/schema/attempt-record.json.
