Qualcomm Interview Question

How to do the depth-first traversal?