> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/04-04-2022-589.-n-ary-tree-preorder-traversal.md).

# 04/04/2022 589. N-ary Tree Preorder Traversal

Method 1:

DFS. add root. val first and then traverse each child of the root.

Time O(n)

Space O(H)

Method 2:

Iteration. Use stack. It is noted that for the children of the root, we need to add each children in the reverse order as the stack is FILO.

Time O(n)

Space O(n)

1.
