<p>Unlike transaction Merkle trees, the taproot script tree does not need to be balanced; i.e., not every leaf needs to be at the same distance from the root.</p>
<p>So there is no need for a &quot;node&quot; with just a single child, and such nodes are in fact not possible. Instead, just construct a tree where the would-be single child is placed one level higher in the tree.</p>

CC BY-SA 4.0
2021-10-30T13:14:28.907Z
I see, I was working under the assumption that the tree was balanced and arbitrary data was used to fill in left over leaves but this makes more sense. Thanks
Keijyu
CC BY-SA 4.0
2021-10-30T01:56:14.630Z
2021-10-30T01:56:14.630Z
Pieter Wuille
<p>I am writing some code implementing taproot address creation where a script path is present and I have a quick question surrounding the reference code.</p>
<p>The BIP-341 reference method <code>taproot_tree_helper(script_tree)</code> will recursively call itself if the parameter is not a tuple (leaf node). When it calls itself, it passes in it's child nodes by:</p>
<pre><code>left, left_h = taproot_tree_helper(script_tree[0])
right, right_h = taproot_tree_helper(script_tree[1])
</code></pre>
<p>What should happen if a node only contains a single child (where script_tree[1] does not exist)? Should it pass in the same node twice for both left and right or should the tree be constructed in a way that this cannot happen?</p>
<p>Thanks</p>

CC BY-SA 4.0
2021-10-30T01:51:11.447Z
Does this answer your question? [Single-leaf script-path example](https://bitcoin.stackexchange.com/questions/110240/single-leaf-script-path-example)
Pieter Wuille
<merkle-tree><taproot>
Can taproot script trees have nodes with a single child?
Keijyu
# Can taproot script trees have nodes with a single child?

(Asked by: username_0 on 2021-10-30)

I am writing some code implementing taproot address creation where a script path is present and I have a quick question surrounding the reference code.

The BIP-341 reference method `taproot_tree_helper(script_tree)` will recursively call itself if the parameter is not a tuple (leaf node). When it calls itself, it passes in it's child nodes by:

```
left, left_h = taproot_tree_helper(script_tree[0])
right, right_h = taproot_tree_helper(script_tree[1])

```

What should happen if a node only contains a single child (where script\_tree[1] does not exist)? Should it pass in the same node twice for both left and right or should the tree be constructed in a way that this cannot happen?

Thanks

**Tags:** merkle-tree, taproot

> **Comments:**
> **username_1**: Does this answer your question? [Single-leaf script-path example](https://bitcoin.stackexchange.com/questions/110240/single-leaf-script-path-example)  

---

## 1 answers

### Answer by username_1 on 2021-10-30. Score: 2 | Accepted answer

Unlike transaction Merkle trees, the taproot script tree does not need to be balanced; i.e., not every leaf needs to be at the same distance from the root.

So there is no need for a "node" with just a single child, and such nodes are in fact not possible. Instead, just construct a tree where the would-be single child is placed one level higher in the tree.

> **Comments:**
> **username_0**: I see, I was working under the assumption that the tree was balanced and arbitrary data was used to fill in left over leaves but this makes more sense. Thanks  

---

