Probability distribution of the number of nodes in a binary tree

132 Views Asked by At

Consider binary trees in which each node has probability $\mathit l \in (0,1)$ of having a left child and probability $\mathit r \in (0,1)$ of having a right child.

What is the probability distribution of the number of nodes in such a binary tree of height $\mathit h$?

This may be a hard question, so I would be grateful for any answer to this question for the simpler case where $\mathit l = \mathit r$ or $\mathit l = 0.5$ and $\mathit r = 0.5$.

Follow up question: what is the probability distribution of the number of nodes in a particular level of such a binary tree of height $\mathit h$?

Motivation: I'm a CS student and I'm interested in comparing the space complexity of a depth-first traversal of such a tree using a stack, $\mathit O(h)$, and the average space complexity of a breadth-first traversal of such a tree using a queue, $\mathit O(the\;maximum\;number\;of\;nodes\;in\;a\;level\;of\;the\;tree)$.