Print a Custom Tree Pattern
Problem Construct a tree matching a given specification and print it in a requested shape — level-order, or an indented/ASCII rendering that visually conveys the structure.
Input / Output
- Input: a construction rule or serialized description of the tree — a level-order array with nulls, a parent→children edge list, or a generative rule such as "each node at depth d has d children" — plus the desired print format.
- Output: the printed pattern: one line per level for level-order, or an indented rendering in which each child is indented deeper than its parent.
Constraints
- The tree may be binary or n-ary; confirm which before building, since it decides between fixed left/right fields and a children list.
- Missing children must either be represented consistently or omitted entirely — clarify which.
- Printing must stay O(n) in the node count, and the exact format (separator, null marker, indentation width) should be nailed down before coding.
Example
- The level-order array
[1,2,3,4,5,null,6]builds a tree that prints level-order as:
1
2 3
4 5 6
- The same tree rendered as an indented DFS at 2 spaces per level:
1
2
4
5
3
6
- The instructive case is node 3's missing left child: 6 must attach as its right child, not slide into the empty left slot.
asked …