AlgoFrames

Nodes at depth d in a full tree

Challenge · Trace the algorithm · about 6 min

In this tree every level is completely filled: each internal node has two children and all leaves share one depth. Predict how many nodes each level holds, then give the rule for any depth d.

Example 1

Input:

{"levelOrder":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]}

Output:

[1,2,4,8]

Levels 0 to 3 hold 1, 2, 4 and 8 nodes.

Constraints

  • Every level is completely filled
  • Depth counts edges from the root

Learn the idea first: Trees: root, leaf, depth, height, subtree, a visual lesson.

More Trees: root, leaf, depth, height, subtree problems