Qualcomm interview question

How to do the depth-first traversal?