root = tree[0]
for i in range(len(tree)):
    l_child_idx, r_child_idx = (i + 1) * 2 - 1, (i + 1) * 2
root_idx = (i + 1) // 2
if root_idx:
    tree[i].root = tree[root_idx]
if l_child_idx < len(tree):
    tree[i].left = tree[l_child_idx]
if r_child_idx < len(tree):
    tree[i].right = tree[r_child_idx]
print(root.height())
Height of binary tree