Microsoft Interview Question

How to traverse the graph