โ† Back to the trees page

N-ary Tree

Any number of children per node. File systems, org charts, and UI component trees are all n-ary.

What to know

  • Children live in a list; traversals loop over it instead of left/right.
  • DFS maps to recursive directory walks; BFS maps to org-chart levels.
  • Left-child/right-sibling encoding converts any n-ary tree to binary.

In the wild: File explorers, React/DOM trees, comment threads, category taxonomies.

Algorithms to reach for

N-ary DFS/BFS

O(n)

Walk file systems, render component trees

Left-child right-sibling encoding

O(n)

Represent n-ary as binary

Practice problems โ€” with full guides

Each problem has its own page: progressive hints, how to approach it, and the full solution.