def _get_node_degrees(walk):
    """
    Converts a random walk to the number of children each node has, following the pre-order of the tree.
    :param walk: A list of integers, starting at 1 and ending at 0, remaining strictly positive between.
    :return: The number of children each node has, ordered by the pre-order of the tree.
    """
    # The walk represents a queue of nodes that have not been given children. Thus, walk[i] - walk[i-1] +1
    # is the number of children that node i receives.
    seq = [walk[1]]
    for i in range(2, len(walk)):
        seq.append(walk[i] - walk[i - 1] + 1)
    return seq