A complete
- - - - [.] - - - -
/ \
/ \
/ \
/ \
(*) (*)
/ \ / \
/ \ / \
/ \ / \
/ \ / \
() () () ()
/ \ / \ / \ / \
/ \ / \ / \ / \
* * * * * 11 12 13
/ \ / \ / \ / \ / \
1 2 3 4 5 6 7 8 9 10
Specifically, levels are numbered from
A leaf is defined as a node in the tree that has 0 children.
In a complete tree, leafs can be either on level
Sometimes, we want our a complete
But when
But how do we know how to split the leaves across these levels?
Assume the 2nd-to-last level
Overall, we would need these two levels together to store all
Now, we can solve for
The problem we'll run into here is that the numerator might not be divisible by the numerator.
One thing we can do is change
That's hacky though.
We'll instead allow level
The new formula for
So, all we need to do is find the
Unfortunately, this will never allow for the case where
*
/ \
/ \
* *
/ \ /
1 2 3
In other words, our formulas above implicitly assume that
We can deal with the problematic case above by identifying it via:
If so, we let