6
4 5
1 2 3 {3}
Total nodes = 6
Leaf nodes = 3
7
5 6
1 2 3 4
Total nodes = 7
Leaf nodes = 4
11
9 10
6 7 8 {8}
1 2 3 4 5 {5}
Total nodes = 11
Leaf nodes = 5
15
13 14
9 10 11 12
1 2 3 4 5 6 7 8
Total nodes = 15
Leaf nodes = 8
Would it be possible to optimise the way that these trees are built?
It doesn't seem quite right hashing the final leaf nodes with themselves when you encounter odd numbers.
How about this:
For each 1 in the binary representation of the number of elements in a set (number of leaf nodes) you build a complete merkle tree. (if there is an odd number then the final tree will just be a single element). Then hash the root of the smallest tree with the root of the second smallest. Hash the result of this with the root of the third smallest etc. until you reach the root of the largest tree and this is your block hash.
As an example, to represent a set of 5 leaf nodes represented in binary by 101 I would build two trees (in fact the final i isn't a tree but just the single element)
So it would look like this.
H1234.5
H12.34
H1.2 H3.4
1 2 3 4 5
Only 4 hashes compared to 6 above.
So for the number 7 (111) we build three trees (one is a single element)
H1234.567
H12.34 H56.7
H1.2 H3.4 H5.6
1 2 3 4 5 6 7
One hash less.
I haven't really examined this idea but at first glance it seems more efficient in number of hashes and in some cases more efficient for validation of the elements. However it also seems too simple so what is wrong with it?