The pieces of information available to us are the number of leaves in a tree and that each internal node must have at least two children. Is there a way to find the upper bound on the total number of nodes in the tree?

# Tag: leaves

## Confusion with “every path from a given node to any of the leaves goes through the same number of black nodes” property of RB trees

One of the properties of Red Black trees is: “every path from a given node/vertex to any of the leaves goes through the same number of black nodes”

Two related questions about this property:

1) is the vertex we start at counted in this black vertex count?

2) is the leaf we end at counted in the black vertex count?

I have a secret theory about both of these questions, but am hoping for confirmation and so shalt not yet reveal it.

## If a body possessed by a user of Magic Jar is Feebleminded, and the possessor leaves the host body, who was Feebleminded?

Consider that I am possessing a host using *magic jar*, and that while I am possessing the host, I am subjected to the *feeblemind* spell and fail my saving throw.

For whatever reason after this, I decide to the leave the host body and return to the container of *magic jar*. Well, now a question arises: who continues to suffer the effects of *feeblemind*?

## Time complexity – Algorithm to find the lowest common ancestor of all deepest leaves

This is the problem statement I came across today.

Given a binary tree, find the lowest common ancestor of all deepest leaves.

I came up with a correct algorithm, but I would like to confirm the running time of this approach.

The algorithm is as follows:

- Traverse the tree and find the deepest level of the tree,
*dmax*. - Traverse the tree and find all leaves at depth
*dmax*. - Given that
=*LCA(A,B,C)*, traverse all nodes found at step 2 and calculate LCA.*LCA(LCA(A,B),C)*

The subroutine for ** LCA(A,B)** is simple. Starting at

*A*, go all the way up to the root and store each visited node in a hashset. Then, starting at

*B*, go up until you find a node which is contained in the hashset.

I know the first two steps of the algorithm are both *O(n)*, where n corresponds to the number of nodes in the tree. However, I am uncertain about the last step.

** LCA(A,B)** subroutine has a linear complexity. But how many nodes, in the worst scenario, can be found at step 2?.

Intuitively, I would argue that it has to be far less than n nodes.

## What’s the number of leaves in AVL tree

How can I prove that the number of leaves in a balanced BST is omega N where N is the number of nodes in the tree?

I tried somehow to prove that an AVL/Fibonacci tree should have omega N leaves by the Fibonacci sequence and didn’t know how to continue!

Could somebody help?

## If Ability Rip leaves you with 0 HD and 0 Class levels, what happens?

Ability rip causes its target, should they lack supernatural abilities, to permanently 2 class levels, or 2 HD if you’ve no class levels (what happens if you have exactly 1 class level is addressed here). Assuming a character with 2 HD and no supernatural abilities, like a typical gnoll, is targetted by Ability Rip the result is a 0 HD gnoll. Since the typical gnoll also has no class levels and isn’t a lycanthrope, this results in a creature with 0 total HD from all sources. How does that work? If the creature is also a PC and playing a LA:+0 race like, e.g., an Anthropomorphic Dromedary Camel, how much XP do they need to reach ECL 1? How much XP does an APL 0 get from a level-appropriate encounter? Basically, how does 0 HD 0 class level PC life work differently than normal PC life?

## What should I do about a character’s magic items when their player leaves?

I have a group of three adventurers and one member of the party is leaving the group permanently. No worries, it’s all on good terms and we’re getting someone else to replace them. My concern is that my group can be fairly volatile, meaning that players come and go somewhat frequently, and I’m not sure what the best way would be to handle their magic items. I could just allow the remaining players to pick through the magic items that belonged to the player who is leaving, but that could cause balance issues if my player count dwindles and they are loaded with unnecessary magic items. Not to mention it doesn’t really make sense for a character to just give up all of their most valuable possessions just because they are retiring from adventuring. On the other hand, I don’t think it would be right for me to rob the party of the hard earned loot that they ALL risk their hides for. Does anyone know if there are guidelines for this scenario, or do you have any advice?

## Prove that maximum number of leaves in a 3-2 tree of height h is 3 power h

I have never heard of 3-2 tree . so just curious to know about it and how will I solve this ?

## Show that,with the array representation for sorting an n-element heap, the leaves are the nodes indexed by n⌊n/2⌋+1,⌊n/2⌋+2,…,n

The Question of the CLRS $ 6.1-7$ exercise reads as:

Show that, with the array representation for sorting an n-element heap, the leaves are the nodes indexed by $ \lfloor n / 2 \rfloor + 1, \lfloor n / 2 \rfloor + 2, \ldots, n⌊n/2⌋+1,⌊n/2⌋+2,…,n$ .

I looked for the solution here: https://walkccc.github.io/CLRS/Chap06/6.1/

The solution was provided like this:

Let’s take the left child of the node indexed by $ \lfloor n / 2 \rfloor + 1.$

\begin{aligned} \text{LEFT}(\lfloor n / 2 \rfloor + 1) & = 2(\lfloor n / 2 \rfloor + 1) \ & > 2(n / 2 – 1) + 2 \ & = n – 2 + 2 \ & = n. \end{aligned}

I can’t understand this statement: $ LEFT(⌊𝑛/2⌋+1) > 2(𝑛/2−1)+2$

Please help me out. Thank you.