#K43227. Average Levels in a Binary Tree
Average Levels in a Binary Tree
Average Levels in a Binary Tree
You are given a binary tree represented in level order. The tree nodes are given as space‐separated tokens, where the token null
represents a missing node. Your task is to compute the average value of the nodes on each level of the tree and output them.
The average for each level is calculated using the formula:
\( \text{average} = \frac{\sum_{i=1}^{n} node_i}{n} \)
where \(n\) is the number of nodes on that level and \(node_i\) is the value of the i-th node at that level.
Print the averages of the levels in order, separated by a space.
inputFormat
The input is provided via standard input (stdin) as a single line containing the level order traversal of the binary tree. Node values are separated by a space. The keyword null
indicates that there is no node in that position.
For example: 3 9 20 null null 15 7
outputFormat
Output a single line with the average of each level of the binary tree. Averages should be represented as floating-point numbers with one decimal place, separated by a space.
## sample3
3.0
</p>