Implement a method to traverse the nodes in a graph using Depth First Search Algorithm. Your method should return an ArrayList of strings in expected order.

Example: apple / \ banana mango / \ / peach strawberry \ / cherry Output :

apple banana peach cherry strawberry mango

Need a **hand?** Try out these hints, one at a time.

The key here is to traverse a

`node`

exhaustively before visiting another `adjacent node`

i.e. lets say if `node n`

which is adjacent to `root r`

is visited then before visiting other `adjacent nodes`

of `root r`

, we need to visit `n's adjacent`

nodes.The best iterative approach would be to make use of `stack`

.
1. Check for the `not null`

condition of the `root node`

, if true, then proceed to below steps.

2. Declare and initialize a `stack`

object to store `Node`

objects.

3. Add the root node to the `stack`

, and mark its `visited`

property to `true`

.

4. Start a loop to run till the `stack`

becomes `empty`

.

5. Within the `loop`

, `Pop`

a `node`

and `print`

its data with a `single space`

.

6. `Push`

all its `adjacent nodes`

to `stack`

.

7. With the end of the `loop`

, `traversal`

will be completed.

public ArrayList<String> depthFirstTraversal(Node rootNode) { }

**C**

**Java**

**Python**